﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using DotSpatial.Controls;
using HAGISV2;



using DotSpatial.Topology;

using System.Windows.Forms;

using HA.Data;
using HA.ModFlow.Domain.DomainLayer;
using HA.ModFlow.Controls.Windows;

using HAUtil;
using HAMath;
using GisContour;

using HA.ModFlow.Infrastructure;
using HA.Data.DisplayOptions2;


namespace HA.ModFlow.Application
{

    /// <summary>
    /// 通用二维处理工具，用于二维辅助绘制等工作
    /// </summary>
    public class GisModule
    {
        protected GisModule()
        {
            _gisManager = new GisManager();

            //订阅对应的事件
            this._gisManager.InteractiveSystem.EditConceptFrame += new EventHandler<EditConceptFrameEventArgs>(this.InteractiveSystem_EditConceptFrame);

            //this._gisManager.InteractiveSystem.AskShapeAdd += new ShapeAddHandler(InteractiveSystem_AskShapeAdd);

            this._gisManager.InteractiveSystem.NewAskShapeAdd+=new NewShapeAddHandler(InteractiveSystem_NewAskShapeAdd);

            this._gisManager.InteractiveSystem.AskAddConvertdPolygon += new ConvertedPolyShapeAddHandler(InteractiveSystem_AskAddConvertedPolyShape);

            this._gisManager.InteractiveSystem.MoveGridCrossPoint += new EventHandler<MoveHGridCrossPointEventArgs>(InteractiveSystem_MoveGridCrossPoint);

            //this._gisManager.InteractiveSystem.HGMSEditShape += new EventHandler<HGMSSelectMFEventArgs>(InteractiveSystem_HGMSEditShapeMF);

            this._gisManager.InteractiveSystem.NewHGMSEditShape+=new EventHandler<HGMSSelectMFEventArgs>(InteractiveSystem_NewHGMSEditShape);

            //this._gisManager.InteractiveSystem.HGMSDeleteShape += new EventHandler<HGMSSelectMFEventArgs>(InteractiveSystem_HGMSDeleteShapeMF);

            this._gisManager.InteractiveSystem.NewHGMSDeleteShape+=new EventHandler<HGMSSelectMFEventArgs>(InteractiveSystem_NewHGMSDeleteShape);

            this._gisManager.InteractiveSystem.HScatter2DOperation+=new EventHandler<Scatter2DPointOperationEventArgs>(InteractiveSystem_HScatter2DOperation);

            this._gisManager.InteractiveSystem.HGMSDoubleClickAttribute+=new EventHandler(InteractiveSystem_HGMSDoubleClickAttribute);

            this._gisManager.InteractiveSystem.GridCellDoubleClickAttri += new EventHandler(miGridAttribute_Click);

            #region 配置右键系统
            ContextMenuStrip menu;
            ToolStripMenuItem mi;

            #region 网格右键

            menu = new ContextMenuStrip();
            mi = new ToolStripMenuItem("属性");
            mi.Click += new EventHandler(miGridAttribute_Click);
            
            menu.Items.Add(mi);

            mi = new ToolStripMenuItem("源汇");
            mi.Click += new EventHandler(miSoureSink_Click);

            menu.Items.Add(mi);


            mi = new ToolStripMenuItem("屏障");
            mi.Click += new EventHandler(miBarrier_Click);
            menu.Items.Add(mi);
            this._gisManager.InteractiveSystem.GridCellSelectContextMenu = menu;

            #endregion

            #region 概念层右键



            menu = new ContextMenuStrip();
            
            mi = new ToolStripMenuItem("端点→节点");
            mi.Click += new EventHandler(miConceptLayerNToV_Click);

            menu.Items.Add(mi);

            menu.Items.Add(new ToolStripSeparator());

            mi = new ToolStripMenuItem("属性表");
            mi.Click += new EventHandler(miAttributeTable_Click);

            menu.Items.Add(mi);


            mi = new ToolStripMenuItem("设置坐标");
            mi.Click += new EventHandler(miConceptLayerSetCoordinate_Click);

            menu.Items.Add(mi);

            this._gisManager.InteractiveSystem.ConceptLayerNodeContextMenu = menu;

            ////////////////////////////////////////////////


            menu = new ContextMenuStrip();

            mi = new ToolStripMenuItem("节点→端点");
            mi.Click += new EventHandler(miConceptLayerVToN_Click);

            menu.Items.Add(mi);

            menu.Items.Add(new ToolStripSeparator());

            mi = new ToolStripMenuItem("设置坐标");
            mi.Click += new EventHandler(miConceptLayerSetCoordinate_Click);

            menu.Items.Add(mi);

            this._gisManager.InteractiveSystem.ConceptLayerVertexContextMenu = menu;

            ///////////////////////////////////////////////
            //menu = new ContextMenu();

            //mi = new MenuItem("waitForFill");
            //mi.Click += new EventHandler(miConceptLayerVToN_Click);

            //menu.MenuItems.Add(mi);

            menu = new ContextMenuStrip();

            mi = new ToolStripMenuItem("属性表");
            mi.Click += new EventHandler(miAttributeTable_Click);

            menu.Items.Add(mi);

            this._gisManager.InteractiveSystem.ConceptLayerLineContextMenu = menu;

            ////////////////////////////////////////////////
            menu = new ContextMenuStrip();

            mi = new ToolStripMenuItem("属性表");
            mi.Click += new EventHandler(miAttributeTable_Click);

            menu.Items.Add(mi);

            mi = new ToolStripMenuItem("设置坐标");
            mi.Click += new EventHandler(miConceptLayerSetCoordinate_Click);

            menu.Items.Add(mi);

            this._gisManager.InteractiveSystem.ConceptLayerPointContextMenu = menu;

            ////////////////////////////////////////////////
            menu = new ContextMenuStrip();

            mi = new ToolStripMenuItem("属性表");
            mi.Click += new EventHandler(miAttributeTable_Click);

            menu.Items.Add(mi);

            this._gisManager.InteractiveSystem.ConceptLayerPolygonContextMenu = menu;

            ////////////////////////////////////////////////

            this._gisManager.InteractiveSystem.ConceptLayerNoneContextMenu = menu;
            #endregion

            #region Scatter2D层右键

            menu = new ContextMenuStrip();

            mi = new ToolStripMenuItem("属性");
            mi.Click += new EventHandler(miScatter2DPointAttr_Click);

            menu.Items.Add(mi);

            menu.Items.Add(new ToolStripSeparator());

            mi = new ToolStripMenuItem("删除");
            mi.Click+=new EventHandler(miScatter2DPointDelete_Click);

            menu.Items.Add(mi);


            this._gisManager.InteractiveSystem.Scatter2DPointContextMenu = menu;

            #endregion

            #endregion
        }


        public static System.Windows. Window mainWindow;

        void CurrentMap_MouseMove(object sender, MouseEventArgs e)
        {
            ////if非2D视图返回

            //Coordinate coord;
            //HydrolicGridLayer hgLayer;
            //Point pt;
            //int i = 0, j = 0, k = 0, id = 0;
            //coord = _gisManager.CurrentMap.PixelToProj(e.Location);
            //pt = new Point(coord);
            ////System.Diagnostics.Debug.WriteLine(coord.ToString());
            //switch (_gisManager.VIEWMODE)
            //{
            //    case FMAPVIEW.NORMAL:
            //        //coord.X X coord.Y Y zz
            //        if((hgLayer= (HydrolicGridLayer)_gisManager.LayerSystem.LayerCollection.GetLayer(""))!=null)
            //        {

            //            for (int m = 0; m < hgLayer.GridPolygons.Count; m++)
            //            {
            //                if (hgLayer.GridPolygons[m].Contains(pt))
            //                {
            //                    i = (m+1) / hgLayer.HyGrid.ColsCount+1;
            //                    j = (m+1) % hgLayer.HyGrid.ColsCount;
            //                    k = hgLayer.ViewLayerIndex;

            //                    break;
            //                }
            //            }
            //        }
            //        break;
            //    case FMAPVIEW.FRONT:
            //        //coord.X X coord.Y Z zy
            //        break;
            //    case FMAPVIEW.RIGHT:
            //        //coord.X Y coord.Y Z zx
            //        break;
            //    default:
            //        break;
            //}

        }

        #region 交互事件订阅函数

        void InteractiveSystem_HScatter2DOperation(object sender, Scatter2DPointOperationEventArgs e)
        {
            foreach (Scatter2D s2d in ProjectService.DefaultService.Project.Scatter2dData.Datas)
            {
                if (s2d.Key.ToString() == e.LayerId)
                {
                    switch (e.OperationMode)
                    {
                        case MFBasicOperationMode.Add:
                            s2d.AddPoint(new ScatterPoint(s2d.GetNextScatterPointId(), e.Values, e.Coord.X, e.Coord.Y));
                            break;
                        case MFBasicOperationMode.Edit:
                            s2d.EditPoint(e.IdForEdit, e.Coord.X, e.Coord.Y, e.Values);
                            break;
                        case MFBasicOperationMode.Delete:
                            s2d.RemovePoint(e.IdsForDelete);
                            break;
                        default:
                            break;
                    }

                    return;
                }
            }
        }

        void InteractiveSystem_EditConceptFrame(object sender, EditConceptFrameEventArgs e)
        {
            ProjectService.DefaultService.Project.MapData.EditGridFrame(e.OrgX, e.OrgY, e.Width, e.Height, e.Rotation);

        }

        //void InteractiveSystem_HGMSDeleteShapeMF(object sender, HGMSSelectMFEventArgs e)
        //{
        //    VectorLayer vectLayer = this._gisManager.LayerSystem.LayerCollection.GetLayer(e.LayerId) as VectorLayer;

        //    if (vectLayer == null) return;
        //    string shapeId = (string)e.FeatureId;
        //    //VectorShape vshape= vectLayer.GetShape(shapeId);

        //    foreach (ConceptualModel cm in ProjectSerivce.DefaultService.Project.MapData.ConceptualModelCL)
        //    {
        //        foreach (Coverage item in cm.Coverages)
        //        {
        //            if (item.Key.ToString().ToLower() == e.LayerId)
        //            {
        //                item.DelectFOShape(shapeId);

        //                return;
        //            }
        //        }
        //    }

        //}

        //void InteractiveSystem_HGMSEditShapeMF(object sender, HGMSSelectMFEventArgs e)
        //{
        //    VectorLayer vectLayer = this._gisManager.LayerSystem.LayerCollection.GetLayer(e.LayerId) as VectorLayer;

        //    if (vectLayer == null) return;
        //    string shapeId = (string)e.FeatureId;
        //    //VectorShape vshape= vectLayer.GetShape(shapeId);

        //    foreach (ConceptualModel cm in ProjectSerivce.DefaultService.Project.MapData.ConceptualModelCL)
        //    {
        //        foreach (Coverage item in cm.Coverages)
        //        {
        //            if (item.Key.ToString().ToLower() == e.LayerId)
        //            {
        //                List<HCoordinate> hcoords = new List<HCoordinate>();


        //                List<List<HCoordinate>> holes = new List<List<HCoordinate>>();
        //                List<HCoordinate> hole;

        //                if (e.NewFeature.BasicGeometry is Polygon)
        //                {
        //                    Polygon py = e.NewFeature.BasicGeometry as Polygon;
        //                    foreach (Coordinate coord in py.ExteriorRing.Coordinates)
        //                    {
        //                        hcoords.Add(new HCoordinate(coord.X, coord.Y));
        //                    }
        //                    hcoords.RemoveAt(hcoords.Count - 1);

        //                    foreach (LinearRing lr in py.Holes)
        //                    {
        //                        hole = new List<HCoordinate>();
        //                        foreach (Coordinate coor in lr.Coordinates)
        //                        {
        //                            HCoordinate hcoord = new HCoordinate(coor.X, coor.Y);
        //                            hole.Add(hcoord);
        //                        }
        //                        hole.RemoveAt(hole.Count - 1);

        //                        if (hole.Count >= 3)
        //                            holes.Add(hole);
        //                    }
        //                }
        //                else
        //                {
        //                    foreach (Coordinate coord in e.NewFeature.BasicGeometry.Coordinates)
        //                    {
        //                        hcoords.Add(new HCoordinate(coord.X, coord.Y));
        //                    }
        //                    if (e.NewFeature.BasicGeometry is LinearRing)
        //                    {
        //                        (item.GetFeatueObject(shapeId) as LineFO).IsEnclosed = true;
        //                        hcoords.RemoveAt(hcoords.Count - 1);
        //                    }
        //                    else if (e.NewFeature.BasicGeometry is LineString)
        //                    {
        //                        (item.GetFeatueObject(shapeId) as LineFO).IsEnclosed = false;
        //                    }
        //                }


        //                //item.ModifyFOShape(shapeId, hcoords, holes, e.IsCoordinateEditMoveNotEditDelete);

        //                return;
        //            }
        //        }
        //    }

        //}

        void InteractiveSystem_MoveGridCrossPoint(object sender, MoveHGridCrossPointEventArgs e)
        {
            ProjectService.DefaultService.Project.Grid3dData.MainGrid.ModFlowGrid.MoveCoords(e.RowIndex, e.ColIndex, e.RowValue, e.ColValue, e.OriginX, e.OriginY);

        }


        /// <summary>
        /// 图形的groupName与MapSCType转换以便对应
        /// </summary>
        /// <param name="groupName"></param>
        /// <returns></returns>
        MAPSCType ShapeGroupConversionStrToType(string groupName)
        {
            if (groupName == null)
                return MAPSCType.NONE;

            switch (groupName.ToLower())
            {
                case "specifiedhead":
                    return MAPSCType.SPECIFIEDHEAD;

                case "ibound":
                    //this._ptLayer.SetCategory(f, this._shapeStyleAndIdStorage[CONCEPTLAYERSOURCESINK.].GetFeatureCategory(MFSHAPETYPE.POINT));
                    break;

                case "specifiedconc":
                    //this._ptLayer.SetCategory(f, this._shapeStyleAndIdStorage[CONCEPTLAYERSOURCESINK.].GetFeatureCategory(MFSHAPETYPE.POINT));
                    break;

                case "specifiedflow":
                    return MAPSCType.SPECIFIEDFLOW;

                case "generalhead":
                    return MAPSCType.GENERALHEAD;

                case "massload":
                    //this._ptLayer.SetCategory(f, this._shapeStyleAndIdStorage[CONCEPTLAYERSOURCESINK.ms].GetFeatureCategory(MFSHAPETYPE.POINT));
                    break;

                case "drain":
                    return MAPSCType.DRAIN;

                case "seepage":
                    return MAPSCType.SEEPAGEFACE;

                case "river":
                    return MAPSCType.RIVER;

                case "barrier":
                    return MAPSCType.BARRIER;

                case "well":
                    return MAPSCType.WELL;

                case "default":
                    return MAPSCType.NONE;

                default:
                    break;
            }
            return MAPSCType.NONE;
        }
        #region 废弃
        //void InteractiveSystem_AskShapeAdd(string groupName, Coordinate[] coords, List<Coordinate[]> holes, MFSHAPETYPE type)
        //{
        //    if (this._gisManager.InteractiveSystem.CurrentLayer == null)
        //    {
        //        return;

        //    }
        //    else
        //    {
        //        Layer currentLayer = this._gisManager.InteractiveSystem.CurrentLayer;
        //        if (currentLayer is VectorLayer)
        //        {
        //            VectorLayer vl = currentLayer as VectorLayer;

        //            if (vl.Parent == null)
        //            {
        //                return;

        //            }

        //            ConceptualModel cm = ProjectSerivce.DefaultService.Project.MapData.GetConcetualModel(vl.Parent.Id);

        //            Coverage c = cm.GetCoverage(vl.Id);



        //            // Coverage c=ProjectSerivce.DefaultService.Project.MapData.get


        //            switch (type)
        //            {
        //                case MFSHAPETYPE.POINT:

        //                    PointFO pt = new PointFO(c.GetNextPointId(), new HAUtil.HCoordinate(coords[0].X, coords[0].Y),c);

        //                    pt.SelectedSCType = ShapeGroupConversionStrToType(groupName);


        //                    c.Add(pt);

        //                    //PointShape ps = new PointShape(this.GisManager.AssistSystem.GetNextPointId(),coords[0]);
        //                    //vl.AddShape(ps);

        //                    break;
        //                case MFSHAPETYPE.LINE:

        //                    List<HCoordinate> hcoord = new List<HCoordinate>();
        //                    for (int i = 0; i < coords.Length; i++)
        //                    {
        //                        HCoordinate coord = new HCoordinate(coords[i].X, coords[i].Y);

        //                        hcoord.Add(coord);

        //                    }

        //                    LineFO ln = new LineFO(c.GetNextLineId(), hcoord,c);

        //                    ln.SelectedSCType = ShapeGroupConversionStrToType(groupName);

        //                    c.Add(ln);


        //                    break;
        //                case MFSHAPETYPE.POLYLINE:
        //                    List<HCoordinate> plCoords = new List<HCoordinate>();
        //                    for (int i = 0; i < coords.Length; i++)
        //                    {
        //                        HCoordinate plCoord = new HCoordinate(coords[i].X, coords[i].Y);

        //                        plCoords.Add(plCoord);

        //                    }

        //                    LineFO polyLine = new LineFO(c.GetNextLineId(), plCoords,c);
        //                    polyLine.IsEnclosed = true;

        //                    polyLine.SelectedSCType = ShapeGroupConversionStrToType(groupName);

        //                    c.Add(polyLine);


        //                    break;
        //                case MFSHAPETYPE.POLYGON:
        //                    List<List<HCoordinate>> polyHoles = new List<List<HCoordinate>>();
        //                    List<HCoordinate> polyHole;
        //                    if (holes != null && holes.Count != 0)
        //                    {
        //                        foreach (Coordinate[] item in holes)
        //                        {
        //                            polyHole = new List<HCoordinate>();

        //                            foreach (Coordinate coordinate in item)
        //                            {
        //                                HCoordinate coord = new HCoordinate(coordinate.X, coordinate.Y);

        //                                polyHole.Add(coord);
        //                            }

        //                            if (polyHole.Count >= 3)
        //                            {
        //                                polyHoles.Add(polyHole);
        //                            }
        //                        }

        //                    }

        //                    List<HCoordinate> phcoord = new List<HCoordinate>();
        //                    for (int i = 0; i < coords.Length; i++)
        //                    {
        //                        HCoordinate coord = new HCoordinate(coords[i].X, coords[i].Y);

        //                        phcoord.Add(coord);

        //                    }


        //                    PolygonFO py = new PolygonFO(c.GetNextPolygonId(), phcoord, polyHoles,c);

        //                    py.SelectedSCType = ShapeGroupConversionStrToType(groupName);

        //                    c.Add(py);


        //                    //PolyShape pls = new PolyShape(this.GisManager.AssistSystem.GetNextPolygonId(),coords);
        //                    //vl.AddShape(pls);


        //                    break;
        //                default:
        //                    break;
        //            }
        //        }
        //    }

        //}
        #endregion

        #region New


        /// <summary>
        /// 替代InteractiveSystem_HGMSDeleteShapeMF
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void InteractiveSystem_NewHGMSDeleteShape(object sender, HGMSSelectMFEventArgs e)
        {
            VectorLayer vectLayer = this._gisManager.LayerSystem.LayerCollection.GetLayer(e.LayerId) as VectorLayer;
            if (vectLayer == null) return;
            if (vectLayer.Parent == null) return;

            ConceptualModel cm = ProjectService.DefaultService.Project.MapData.GetConcetualModel(vectLayer.Parent.Id);
            Coverage coverage = cm.GetCoverage(vectLayer.Id);

            coverage.Remove(e.FeatureIds);

        }


        /// <summary>
        /// 替代InteractiveSystem_HGMSEditShapeMF
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void InteractiveSystem_NewHGMSEditShape(object sender, HGMSSelectMFEventArgs e)
        {

            //编辑操做包括：普通点、线内部点、线端点的删除移动及线内部点的变动——即线、Node、Point的所有变动。   保补充

            VectorLayer vectLayer = this._gisManager.LayerSystem.LayerCollection.GetLayer(e.LayerId) as VectorLayer;
            if (vectLayer == null) return;
            if (vectLayer.Parent == null) return;

            ConceptualModel cm = ProjectService.DefaultService.Project.MapData.GetConcetualModel(vectLayer.Parent.Id);
            Coverage coverage = cm.GetCoverage(vectLayer.Id);

            //图形变动集合
            List<string> ids = new List<string>();

            for (int i = 0; i < e.FeatureIds.Count; i++)
            {
                
                FeatureObject fo = coverage.GetFeatueObject(e.FeatureIds[i]);

                if (ids.Contains(fo.Id))
                    continue;

                ids.Add(fo.Id);

                if (fo is PointFO)
                {
                    (fo as PointFO).Coords = new HCoordinate(e.NewCoordinates[0][0].X, e.NewCoordinates[0][0].Y);
                }
                else if (fo is NodeFO)
                {
                    //如果移动的是节点，就会分两种情况
                    //1 是普通的节点，直接改变坐标即可
                    //2 是线上的节点，改变点坐标的同时，还要改变线对应的多边形的坐标
                    (fo as NodeFO).Position = new HCoordinate(e.NewCoordinates[0][0].X, e.NewCoordinates[0][0].Y);


                    (fo as NodeFO).UpdateForVertexChanged(CollectionChangedType.MOVE, ref ids); //与点相关的线的编辑，直接封装在这个函数内


                }
                else if (fo is LineFO)
                {
                    //如果是对线的操做，也是两种情况
                    //1 普通点的移动
                    //2 普通点的删除
                    //但是这两种情况都按一种方法来算，即将新生成的图形的坐标直接赋给旧图形即可


                    //if (e.NewCoordinates[i].Count < 2)
                    //    return; //如果点的个数小于2个，出错

                    List<HCoordinate> coorLst = new List<HCoordinate>();
                    for (int j = 0; j < e.NewCoordinates[i].Count; j++)
                    {
                        coorLst.Add(new HCoordinate(e.NewCoordinates[i][j].X, e.NewCoordinates[i][j].Y));
                    }

                    (fo as LineFO).Coords = coorLst;

                    (fo as LineFO).UpdateForLineChanged(CollectionChangedType.MOVE, ref ids);  //与线相关的多边形的编辑，封装在这个函数内

                }

            }
            
            coverage.ModifyFOShape(ids);

        }

        /// <summary>
        /// 替代InteractiveSystem_AskShapeAdd
        /// </summary>
        /// <param name="groupName"></param>
        /// <param name="coords"></param>
        /// <param name="holes"></param>
        /// <param name="type"></param>
        void InteractiveSystem_NewAskShapeAdd(string groupName, Coordinate[] coords, List<string> vertexIds, MFSHAPETYPE type, Dictionary<List<int>, Coordinate> lineBreak = null)
        {
            if (this._gisManager.InteractiveSystem.CurrentLayer == null)
                return;
            Layer currentLayer = this._gisManager.InteractiveSystem.CurrentLayer;
            if (currentLayer is VectorLayer)
            {
                VectorLayer vl = currentLayer as VectorLayer;

                if (vl.Parent == null)
                    return;

                ConceptualModel cm = ProjectService.DefaultService.Project.MapData.GetConcetualModel(vl.Parent.Id);

                Coverage c = cm.GetCoverage(vl.Id);

                switch (type)
                {
                    case MFSHAPETYPE.POINT:

                        PointFO pt = new PointFO(c.GetNextPointId(), new HAUtil.HCoordinate(coords[0].X, coords[0].Y),c);

                        pt.SelectedSCType = ShapeGroupConversionStrToType(groupName);

                        c.Add(pt);

                        break;
                    case MFSHAPETYPE.LINE:

                        FeatureObject fo;
                        FeatureObject foEnd;
                        NodeFO nodeStart;
                        NodeFO nodeEnd=null;
                        LineFO lineStart;
                        LineFO lineEnd;
                        LineFO newLine=null;
                        List<string> breakLinesId = new List<string>();

                        //添加过滤重复线段逻辑
                        if (coords.Length == 2 && vertexIds[0] != null && vertexIds[0] != "" && vertexIds[1] != null && vertexIds[1] != "")
                        {
                            fo = c.GetFeatueObject(vertexIds[0]);
                            foEnd = c.GetFeatueObject(vertexIds[1]);

                            if (fo is NodeFO)
                            {
                                nodeStart = (NodeFO)fo;

                                if (foEnd is NodeFO)
                                {
                                    nodeEnd = (NodeFO)foEnd;

                                    foreach (LineFO item in nodeStart.RelationLines)
                                    {
                                        if(item.Coords.Count==0)
                                            if (item.VertexStart.Id == nodeEnd.Id || item.VertexEnd.Id == nodeEnd.Id)
                                            {
                                                MessageBox.Show("线段不可重复！");
                                                if (this._gisManager.InteractiveSystem.CurrentLayer is VectorLayer)
                                                    (this._gisManager.InteractiveSystem.CurrentLayer as VectorLayer).LnLayer.Invalidate();
                                                return;
                                            }
                                    }

                                }
                                else
                                {
                                    lineEnd = (LineFO)foEnd;

                                    foreach (LineFO item in nodeStart.RelationLines)
                                    {
                                        if (item == lineEnd)
                                            if (item.VertexStart.Id == nodeStart.Id)
                                            {
                                                if (lineBreak != null)
                                                {
                                                    foreach (var key in lineBreak.Keys)
                                                    {
                                                        if (lineBreak[key].Equals2D(coords[1]))
                                                        {
                                                            if (key[0] == 1&&key[1]==0)
                                                            {
                                                                MessageBox.Show("线段不可重复！");
                                                                if (this._gisManager.InteractiveSystem.CurrentLayer is VectorLayer)
                                                                    (this._gisManager.InteractiveSystem.CurrentLayer as VectorLayer).LnLayer.Invalidate();
                                                                return;
                                                            }
                                                            break;
                                                        }
                                                    }
                                                }

                                                if (coords[1].X == item.Coords[0].X && coords[1].Y == item.Coords[0].Y)
                                                {
                                                    MessageBox.Show("线段不可重复！");
                                                    if (this._gisManager.InteractiveSystem.CurrentLayer is VectorLayer)
                                                        (this._gisManager.InteractiveSystem.CurrentLayer as VectorLayer).LnLayer.Invalidate();
                                                    return;
                                                }
                                            }
                                            else
                                            {
                                                if (lineBreak != null)
                                                {
                                                    foreach (var key in lineBreak.Keys)
                                                    {
                                                        if (lineBreak[key].Equals2D(coords[1]))
                                                        {
                                                            if (key[0] == 1 && key[1] == ((item.Coords.Count - 1) < 0 ? 0 : (item.Coords.Count - 1)))
                                                            {
                                                                MessageBox.Show("线段不可重复！");
                                                                if (this._gisManager.InteractiveSystem.CurrentLayer is VectorLayer)
                                                                    (this._gisManager.InteractiveSystem.CurrentLayer as VectorLayer).LnLayer.Invalidate();
                                                                return;
                                                            }
                                                            break;
                                                        }
                                                    }
                                                }

                                                if (coords[1].X == item.Coords[item.Coords.Count - 1].X && coords[1].Y == item.Coords[item.Coords.Count - 1].Y)
                                                {
                                                    MessageBox.Show("线段不可重复！");
                                                    if (this._gisManager.InteractiveSystem.CurrentLayer is VectorLayer)
                                                        (this._gisManager.InteractiveSystem.CurrentLayer as VectorLayer).LnLayer.Invalidate();
                                                    return;
                                                }
                                            }
                                    }
                                }
                            }
                            else
                            {
                                lineStart = (LineFO)fo;

                                if (foEnd is NodeFO)
                                {
                                    nodeEnd = (NodeFO)foEnd;

                                    foreach (LineFO item in nodeEnd.RelationLines)
                                    {
                                        if (item == lineStart)
                                            if (item.VertexStart.Id == nodeEnd.Id)
                                            {
                                                if (lineBreak != null)
                                                {
                                                    foreach (var key in lineBreak.Keys)
                                                    {
                                                        if (lineBreak[key].Equals2D(coords[0]))
                                                        {
                                                            if (key[0] == 0 && key[1] == 0)
                                                            {
                                                                MessageBox.Show("线段不可重复！");
                                                                if (this._gisManager.InteractiveSystem.CurrentLayer is VectorLayer)
                                                                    (this._gisManager.InteractiveSystem.CurrentLayer as VectorLayer).LnLayer.Invalidate();
                                                                return;
                                                            }
                                                            break;
                                                        }
                                                    }
                                                }

                                                if (coords[0].X == item.Coords[0].X && coords[0].Y == item.Coords[0].Y)
                                                {
                                                    MessageBox.Show("线段不可重复！");
                                                    if (this._gisManager.InteractiveSystem.CurrentLayer is VectorLayer)
                                                        (this._gisManager.InteractiveSystem.CurrentLayer as VectorLayer).LnLayer.Invalidate();
                                                    return;
                                                }
                                            }
                                            else
                                            {
                                                if (lineBreak != null)
                                                {
                                                    foreach (var key in lineBreak.Keys)
                                                    {
                                                        if (lineBreak[key].Equals2D(coords[0]))
                                                        {
                                                            if (key[0] == 0 && key[1] == ((item.Coords.Count - 1) < 0 ? 0 : (item.Coords.Count - 1)))
                                                            {
                                                                MessageBox.Show("线段不可重复！");
                                                                if (this._gisManager.InteractiveSystem.CurrentLayer is VectorLayer)
                                                                    (this._gisManager.InteractiveSystem.CurrentLayer as VectorLayer).LnLayer.Invalidate();
                                                                return;
                                                            }
                                                            break;
                                                        }
                                                    }
                                                }

                                                if (coords[0].X == item.Coords[item.Coords.Count - 1].X && coords[0].Y == item.Coords[item.Coords.Count - 1].Y)
                                                {
                                                    MessageBox.Show("线段不可重复！");
                                                    if (this._gisManager.InteractiveSystem.CurrentLayer is VectorLayer)
                                                        (this._gisManager.InteractiveSystem.CurrentLayer as VectorLayer).LnLayer.Invalidate();
                                                    return;
                                                }
                                            }
                                    }
                                }
                                else
                                {
                                    lineEnd = (LineFO)foEnd;

                                    if (lineEnd == lineStart)
                                    {
                                        if (lineBreak != null)
                                        {
                                            var keys = lineBreak.Keys.ToArray();

                                            try
                                            {
                                                if (keys[0][1] == keys[1][1])
                                                {
                                                    MessageBox.Show("线段不可重复！");
                                                    if (this._gisManager.InteractiveSystem.CurrentLayer is VectorLayer)
                                                        (this._gisManager.InteractiveSystem.CurrentLayer as VectorLayer).LnLayer.Invalidate();
                                                    return;
                                                }
                                            }
                                            catch
                                            {

                                            }
                                        }
                                    }
                                        //for (int i = 0; i < lineEnd.Coords.Count; i++)
                                        //{
                                        //    if (lineStart.Coords[i].X == coords[0].X && lineStart.Coords[i].Y == coords[0].Y)
                                        //    {
                                        //        if (i == 0)
                                        //        {
                                        //            if (lineStart.Coords[i + 1].X == coords[1].X && lineStart.Coords[i + 1].Y == coords[1].Y)
                                        //            {
                                        //                MessageBox.Show("线段不可重复！");
                                        //                return;
                                        //            }
                                        //        }
                                        //        else if (i == lineEnd.Coords.Count - 1)
                                        //        {
                                        //            if (lineStart.Coords[i - 1].X == coords[1].X && lineStart.Coords[i - 1].Y == coords[1].Y)
                                        //            {
                                        //                MessageBox.Show("线段不可重复！");
                                        //                return;
                                        //            }
                                        //        }
                                        //        else
                                        //        {
                                        //            if ((lineStart.Coords[i - 1].X == coords[1].X && lineStart.Coords[i - 1].Y == coords[1].Y) || (lineStart.Coords[i + 1].X == coords[1].X && lineStart.Coords[i + 1].Y == coords[1].Y))
                                        //            {
                                        //                MessageBox.Show("线段不可重复！");
                                        //                return;
                                        //            }
                                        //        }
                                        //    }
                                        //}
                                }
                            }
                        }
                        //与图层当前图形无交集且自身闭合的线
                        if (vertexIds[0] == "Same")
                        {
                            nodeStart = new NodeFO(c.GetNextNodeId(), new HCoordinate(coords[0].X, coords[0].Y), c);
                            nodeEnd = nodeStart;
                        }
                        else
                        {
                            if (vertexIds[0] == null || vertexIds[0] == "")
                            {
                                nodeStart = new NodeFO(c.GetNextNodeId(), new HCoordinate(coords[0].X, coords[0].Y), c);
                            }
                            else
                            {
                                fo = c.GetFeatueObject(vertexIds[0]);
                                if (fo is NodeFO)
                                    nodeStart = (NodeFO)fo;
                                else
                                {
                                    lineStart = (LineFO)fo;
                                    //主程线需做相应的截断处理！涉及多边形更新
                                    //占位 待添加。

                                    //nodeStart = new NodeFO(c.GetNextNodeId(), new HCoordinate(coords[0].X, coords[0].Y),c);


                                    //============================================刘加，线的打断===========================================//
                                    //思路，先对线插入一个普通点，再将这个普通点转换成节点，变成了两条线。旧线修改，新生成的线添加
                                    int insertIndex = lineStart.InsertVertex(new HCoordinate(coords[0].X, coords[0].Y));

                                    //普通点转换成节点，同时生成一条新线。旧线坐标在此函数更改
                                    newLine = lineStart.VertexToNode(insertIndex, ref breakLinesId);
                                    c.Add(newLine); //添加新线

                                    lineStart.UpdateForLineChanged(CollectionChangedType.ITEMEDIT, new List<LineFO>() { newLine }); //更新旧线与新线的信息

                                    c.ModifyFOShape(new List<string>() { lineStart.Id }); //这一句怎么说呢……

                                    if (newLine.VertexStart.Node.Position.X == coords[0].X && newLine.VertexStart.Node.Position.Y == coords[0].Y)
                                    {
                                        nodeStart = newLine.VertexStart.Node;
                                    }
                                    else
                                    {
                                        nodeStart = newLine.VertexEnd.Node;
                                    }

                                    if (coords[coords.Length - 1].X == coords[0].X && coords[coords.Length - 1].Y == coords[0].Y)
                                    {
                                        nodeEnd = nodeStart;
                                    }

                                    breakLinesId.Add(lineStart.Id);
                                    breakLinesId.Add(newLine.Id);

                                    //======================================================================================================//

                                }

                            }
                            if (vertexIds[1] == null || vertexIds[1] == "")
                            {

                                if (lineBreak != null && lineBreak.Count == 2)
                                {
                                    if (lineBreak.Values.ToArray()[0].Equals(lineBreak.Values.ToArray()[1]))
                                    {
                                        nodeEnd = nodeStart;
                                    }
                                }
                                else
                                {
                                    nodeEnd = new NodeFO(c.GetNextNodeId(), new HCoordinate(coords[coords.Length - 1].X, coords[coords.Length - 1].Y), c);
                                }
                            }
                            else
                            {
                                fo = c.GetFeatueObject(vertexIds[1]);
                                if (fo is NodeFO)
                                    nodeEnd = (NodeFO)fo;
                                else
                                {
                                    lineEnd = (LineFO)fo;
                                    //主程线需做相应的截断处理！涉及多边形更新
                                    //占位 待添加。
                                    if (breakLinesId.Contains(lineEnd.Id))
                                    {
                                        //判断另一个
                                        //两个点在同一条线的逻辑

                                        bool isLineEnd = false;

                                        //foreach (HCoordinate coor in lineEnd.Coords)
                                        //{
                                        //    if (coor.X == coords[coords.Length - 1].X && coor.Y == coords[coords.Length - 1].Y)
                                        //    {
                                        //        isLineEnd = true;
                                        //        break;
                                        //    }
                                        //}

                                        List<HCoordinate> coorLst = new List<HCoordinate>();
                                        coorLst.AddRange(lineEnd.ToCoordinatesArray().ToArray());

                                        for (int i = 0; i < coorLst.Count - 1; i++)
                                        {
                                            //快速判断分割点在线上哪两个点之间
                                            if (coords[coords.Length - 1].X > Math.Max(coorLst[i].X, coorLst[i + 1].X) ||
                                                coords[coords.Length - 1].X < Math.Min(coorLst[i].X, coorLst[i + 1].X) ||
                                                coords[coords.Length - 1].Y > Math.Max(coorLst[i].Y, coorLst[i + 1].Y) ||
                                                coords[coords.Length - 1].Y < Math.Min(coorLst[i].Y, coorLst[i + 1].Y))
                                            {
                                                continue;
                                            }

                                            //矢量叉积法判断分割点在当前线段的哪个方向
                                            double value = (coords[coords.Length - 1].X - coorLst[i + 1].X) * (coorLst[i].Y - coorLst[i + 1].Y) - (coorLst[i].X - coorLst[i + 1].X) * (coords[coords.Length - 1].Y - coorLst[i + 1].Y);

                                            if (value == 0 || Math.Abs(value) < 0.0000001) //叉积为0则在线上,后面的是防误差
                                            {
                                                isLineEnd = true;
                                                break;
                                            }

                                        }

                                        if (isLineEnd == false)
                                        {
                                            lineEnd = newLine;
                                        }


                                    }
                                    //else //非断在同一条线上的逻辑
                                    //{
                                    //nodeEnd = new NodeFO(c.GetNextNodeId(), new HCoordinate(coords[coords.Length - 1].X, coords[coords.Length - 1].Y));

                                    //============================================刘加，线的打断===========================================//
                                    if (coords[0].X != coords[coords.Length - 1].X && coords[0].Y != coords[coords.Length - 1].Y)
                                    {

                                        int insertIndex = lineEnd.InsertVertex(new HCoordinate(coords[coords.Length - 1].X, coords[coords.Length - 1].Y));

                                        newLine = lineEnd.VertexToNode(insertIndex, ref breakLinesId);

                                        c.Add(newLine);

                                        lineEnd.UpdateForLineChanged(CollectionChangedType.ITEMEDIT, new List<LineFO>() { newLine });

                                        c.ModifyFOShape(new List<string>() { lineEnd.Id });  //这一句怎么说呢……

                                        if (coords[coords.Length - 1].X == newLine.VertexStart.Node.Position.X && coords[coords.Length - 1].Y == newLine.VertexStart.Node.Position.Y)
                                        {
                                            nodeEnd = newLine.VertexStart.Node;
                                        }
                                        else
                                        {
                                            nodeEnd = newLine.VertexEnd.Node;
                                        }
                                    }
                                    //}

                                    //========================================================================================================//



                                }
                            }
                        }


                        List<HCoordinate> hcoord = new List<HCoordinate>();
                        for (int i = 1; i < coords.Length-1; i++)
                        {
                            HCoordinate coord = new HCoordinate(coords[i].X, coords[i].Y);

                            hcoord.Add(coord);
                        }

                        LineFO ln = new LineFO(c.GetNextLineId(), nodeStart, nodeEnd, hcoord,c);

                        ln.SelectedSCType = ShapeGroupConversionStrToType(groupName);

                        c.Add(ln);


                        break;
                    default:
                        break;
                }
            }

        }
              

        #endregion


        void InteractiveSystem_AskAddConvertedPolyShape(string groupName, string polylineKey, Coordinate[] coords, List<Coordinate[]> holes)
        {
            if (this._gisManager.InteractiveSystem.CurrentLayer == null)
                return;

            Layer currentLayer = this._gisManager.InteractiveSystem.CurrentLayer;
            if (currentLayer is VectorLayer)
            {
                VectorLayer vl = currentLayer as VectorLayer;

                if (vl.Parent == null)
                {
                    return;
                }

                ConceptualModel cm = ProjectService.DefaultService.Project.MapData.GetConcetualModel(vl.Parent.Id);

                Coverage c = cm.GetCoverage(vl.Id);



                List<List<HCoordinate>> polyHoles = new List<List<HCoordinate>>();
                List<HCoordinate> polyHole;
                if (holes != null && holes.Count != 0)
                {
                    foreach (Coordinate[] item in holes)
                    {
                        polyHole = new List<HCoordinate>();

                        foreach (Coordinate coordinate in item)
                        {
                            HCoordinate coord = new HCoordinate(coordinate.X, coordinate.Y);

                            polyHole.Add(coord);
                        }

                        if (polyHole.Count >= 3)
                        {
                            polyHoles.Add(polyHole);
                        }
                    }

                }

                List<HCoordinate> phcoord = new List<HCoordinate>();
                for (int i = 0; i < coords.Length; i++)
                {
                    HCoordinate coord = new HCoordinate(coords[i].X, coords[i].Y);

                    phcoord.Add(coord);
                }


                PolygonFO py = new PolygonFO(c.GetNextPolygonId(), polylineKey, phcoord, polyHoles,c);

                py.SelectedSCType = ShapeGroupConversionStrToType(groupName);

                c.Add(py);
            }

        }

        void InteractiveSystem_HGMSDoubleClickAttribute(object sender,EventArgs e)
        {
            this.miAttributeTable_Click(null, e);
        }


        #endregion

        #region 右键菜单订阅函数

        //障碍物事件
        void miBarrier_Click(object sender, EventArgs e)
        {
            HydrolicGridLayer hyLayer = (HydrolicGridLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(this.GridLayerId);
            if (hyLayer == null)
            {
                return;
            }
            if (ProjectService.DefaultService.Project.MfData == null)
            {
                return;
            }
            if (!ProjectService.DefaultService.Project.MfData.HfbData.Enabled)
            {
                MessageBox.Show("Modflow 屏障包必须被选中才可以添加屏障", "提示", MessageBoxButtons.OK);
                return;
            }

            List<int[]> cell = new List<int[]>();
            for (int i = 0; i < hyLayer.SelectedCellIndexes.Count; i++)
            {
                cell.Add(ProjectService.DefaultService.Project.MfData.GridData.GetIJK(hyLayer.SelectedCellIndexes[i]));
            }
            if (cell.Count != 2)
            {
                MessageBox.Show("必须选择相邻的两个单元格", "提示", MessageBoxButtons.OK);
                return;
            }


            if (cell[0][0] == cell[1][0])
            {
                if (Math.Abs(cell[0][1] - cell[1][1]) == 1)
                {

                }
                else
                {
                    MessageBox.Show("必须选择相邻的两个单元格", "提示", MessageBoxButtons.OK);
                    return;
                }
            }
            else
            {
                if (Math.Abs(cell[0][0] - cell[1][0]) == 1 && cell[0][1] == cell[1][1])
                {
                }
                else
                {
                    MessageBox.Show("必须选择相邻的两个单元格", "提示", MessageBoxButtons.OK);
                    return;
                }
            }



            bool b = false;
            int index = 0;
            HA.ModFlow.Domain.DomainLayer.HFBItem barrier = ProjectService.DefaultService.Project.MfData.HfbData.GetBarrier(ref  b, cell, ref index);
            winManualAddBarrier win = new winManualAddBarrier(barrier, b);
            if (win.ShowDialog().Value)
            {
                List<HA.ModFlow.Domain.DomainLayer.HFBItem> arry = ProjectService.DefaultService.Project.MfData.HfbData.AddOrDelBarrier(win.IsBarrier, win.Barrier, cell);

                ProjectService.DefaultService.Project.MfData.HfbData.ResetHFBDatas(arry);
            }



        }


        //坐标设置按钮事件
        void miConceptLayerSetCoordinate_Click(object sender, EventArgs e)
        {
            VectorLayer layer = this._gisManager.InteractiveSystem.CurrentLayer as VectorLayer;
            if (layer == null || layer.Parent == null)
            {
                return;
            }

             if (!layer.IsSetCoorEffective)
            {
                MessageBox.Show("请选中一个点进行编辑！");
                return;
            }

            

             foreach (MapFunction item in this.DefaultMap.MapFunctions)
             {
                 if (item is HGMSSelectMF)
                 {

                     if ((item as HGMSSelectMF).RightSelectShp.Count != 1)
                     {
                         MessageBox.Show("出错！");
                         return;
                     }

                     string cmId = layer.Parent.Id;

                     //获取要修改的图层
                     Coverage c = ProjectService.DefaultService.Project.MapData.GetConcetualModel(cmId).GetCoverage(layer.Id);

                     HCoordinate coor = new HCoordinate();

                     string shpId = (item as HGMSSelectMF).RightSelectShp.Keys.ToArray()[0];

                     FeatureObject fo = c.GetFeatueObject(shpId);

                     if (fo is LineFO)
                     {
                         coor = (fo as LineFO).ToCoordinatesArray()[(item as HGMSSelectMF).RightSelectShp[shpId]];
                         //coor.Y = (fo as LineFO).ToCoordinatesArray()[(item as HGMSSelectMF).RightSelectShp[shpId]].Y;
                     }
                     else if (fo is NodeFO)
                     {
                         coor = (fo as NodeFO).Position;
                         //coor.Y = (fo as NodeFO).Position.Y;
                     }
                     else
                     {
                         coor = (fo as PointFO).Coords;
                         //coor.Y = (fo as PointFO).Coords.Y;

                     }

                     winTwoTextBox win = new winTwoTextBox(coor.X, coor.Y);

                     win.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;

                     win.Owner = mainWindow;
                     win.ResizeMode = System.Windows.ResizeMode.NoResize;
                     win.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
                     if (win.ShowDialog() == true)
                     {
                         coor.X = win.CoordinateX;
                         coor.Y = win.CoordinateY;
                         List<string> ids = new List<string>();
                         ids.Add(fo.Id);
                         if (fo is NodeFO)
                         {
                             (fo as NodeFO).UpdateForVertexChanged(CollectionChangedType.MOVE, ref  ids);
                         }
                         else if (fo is LineFO)
                         {
                             (fo as LineFO).UpdateForLineChanged(CollectionChangedType.MOVE, ref  ids);
                         }
                         else
                         {

                         }
                         c.ModifyFOShape(ids);
                     }
                     return;
                 }
             }
        }


        //属性表
        void miAttributeTable_Click(object sender, EventArgs e)
        {

            Layer layer = this._gisManager.InteractiveSystem.CurrentLayer;

            if (layer == null)
            {
                return;

            }
            if (layer.Parent == null)
            {
                return;

            }



            string cmId = layer.Parent.Id;

            Coverage c = ProjectService.DefaultService.Project.MapData.GetConcetualModel(cmId).GetCoverage(layer.Id);

            //Controls.Windows.MapData.winCoverageAttributeTable win = new Controls.Windows.MapData.winCoverageAttributeTable(c);


            Controls.Windows.MapData.winAttributeV2 win = new Controls.Windows.MapData.winAttributeV2(c, ProjectService.DefaultService.Project.Units);

            // win.SetSelectedId();

            VectorLayer vl = layer as VectorLayer;

            List<string> ids = new List<string>();


            foreach (FShape shp in vl.SelectedShapes)
            {
                ids.Add(shp.Id);

            }


            win.SetSelectedId(ids);
            if (ids.Count < 1)
                return;

            win.Owner = mainWindow;
            win.ResizeMode = System.Windows.ResizeMode.NoResize;
            win.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
            if (win.ShowDialog() == true)
            {
                c.ResetFOSCTypes(win.AttributeTable.NewFeatureObjects);
            }


        }

        //源汇
        void miSoureSink_Click(object sender, EventArgs e)
        {
            HydrolicGridLayer layer = (HydrolicGridLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(GridLayerId);


            if (layer != null && layer.SelectedCellIndexes.Count > 0)
            {
                if (ProjectService.DefaultService.Project.MfData != null)
                {
                    winSourcesSinks winsource = new winSourcesSinks(ProjectService.DefaultService.Project.MfData, layer.SelectedCellIndexes);
                    winsource.Owner = mainWindow;
                    winsource.ResizeMode = System.Windows.ResizeMode.NoResize;
                    winsource.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
                    winsource.ShowDialog();
                }
            }

        }

        void miGridAttribute_Click(object sender, EventArgs e)
        {
            HydrolicGridLayer layer = (HydrolicGridLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(GridLayerId);

            if (layer != null && layer.SelectedCellIndexes.Count > 0)
            {

                List<int> cellIndexs = layer.SelectedCellIndexes;
                HA.ModFlow.Controls.PresentationClass.PCMt3dGridCellProperty cell = new Controls.PresentationClass.PCMt3dGridCellProperty();
                winGridCellV2 win = new winGridCellV2(ProjectService.DefaultService.Project, cellIndexs,cell);
                win.Owner = mainWindow;
                win.ResizeMode = System.Windows.ResizeMode.NoResize;
                win.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
                if (win.ShowDialog() == true)
                {
                    win.GridCell.Confirm(ProjectService.DefaultService.Project);                 
                    //cell.SetData(ProjectSerivce.DefaultService.Project, cellIndexs);
                }

                //if (win.ShowDialog==System.Windows.di)
                //{



                //}

                //WaterCell cell = ProjectSerivce.DefaultService.Project.GetCell(cellIndexs[0]);



                //winCellProperties winCell = new winCellProperties(cellIndexs, ProjectSerivce.DefaultService.Project.MfData.ModelOption, cell);

                //winCell.ShowDialog();

                //if (winCell.DialogResult == true)
                //{
                //    ProjectSerivce.DefaultService.Project.SetCell(winCell.Cell, cellIndexs);
                //}

            }

        }

        /// <summary>
        /// 节点到端点的转换
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void miConceptLayerVToN_Click(object sender, EventArgs e)
        {
            foreach (MapFunction item in this.DefaultMap.MapFunctions)
            {
                if (item is HGMSSelectMF)
                {
                    //((HGMSSelectMF)item).ClipFeatureByVertex();

                    ConceptualModel cm = ProjectService.DefaultService.Project.MapData.GetConcetualModel(this.GisManager.InteractiveSystem.CurrentLayer.Parent.Id);

                    Coverage coverage = cm.GetCoverage(this.GisManager.InteractiveSystem.CurrentLayer.Id);

                    List<string> ids = new List<string>();

                    foreach (KeyValuePair<LineShape, List<int>> line in (item as HGMSSelectMF).SelectedVertexs)
                    {
                        ids.Add(line.Key.Id);

                        LineFO linefo = coverage.GetFeatueObject(line.Key.Id) as LineFO;
                        if (linefo == null) return; //出错


                        List<LineFO> newLines = new List<LineFO>();
                        newLines = linefo.VertexToNode(line.Value);
                        
                        foreach (LineFO lineItem in newLines)
                        {
                            coverage.Add(lineItem);
                        }

                        //添加一句更新代码
                        linefo.UpdateForLineChanged(CollectionChangedType.ITEMEDIT, newLines);

                    }

                    (item as HGMSSelectMF).SelectedVertexs.Clear();

                    coverage.ModifyFOShape(ids);

                    return;
                }
            }
        }

        /// <summary>
        /// 端点到节点的转换
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void miConceptLayerNToV_Click(object sender, EventArgs e)
        {
            foreach (MapFunction item in this.DefaultMap.MapFunctions)
            {
                if (item is HGMSSelectMF)
                {
                    //((HGMSSelectMF)item).UnionFeatureByNode();

                    List<string> strIds = new List<string>();

                    foreach (NodeShape node in (item as HGMSSelectMF).SelectedNodes)
                    {
                        strIds.Add(node.Id);
                    }

                    ConceptualModel cm = ProjectService.DefaultService.Project.MapData.GetConcetualModel(this.GisManager.InteractiveSystem.CurrentLayer.Parent.Id);
                    Coverage coverage = cm.GetCoverage(this.GisManager.InteractiveSystem.CurrentLayer.Id);

                    coverage.NodeToVertex(strIds);

                    (item as HGMSSelectMF).SelectedNodes.Clear();

                    return;
                }
            }
        }

        /// <summary>
        /// scatter2D点属性
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void miScatter2DPointAttr_Click(object sender, EventArgs e)
        {
            Layer layer = this._gisManager.InteractiveSystem.CurrentLayer;

            if (layer == null)
            {
                return;
            }
            if (layer.Parent == null)
            {
                return;
            }

            Scatter2D s = (Scatter2D)ProjectService.DefaultService.Project.Scatter2dData.GetDataById(layer.Id).Clone();


            //Controls.Windows.MapData.winAttributeV2 win = new Controls.Windows.MapData.winAttributeV2(s);

            ScatterPointLayer spl = layer as ScatterPointLayer;
            List<ScatterPoint> scatter = new List<ScatterPoint>();
            foreach (string id in spl.SelectedShapeIds)
            {
                scatter.Add((ScatterPoint)s.GetPoint(id));

            }

            if (scatter != null)
            {
                HA.ModFlow.Controls.Windows.Scatter.winScatter2DPoints win = new Controls.Windows.Scatter.winScatter2DPoints(scatter, s.Name);
                win.Owner = mainWindow;
                win.ResizeMode = System.Windows.ResizeMode.NoResize;
                win.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
                if (win.ShowDialog().Value)
                {
                    ProjectService.DefaultService.Project.Scatter2dData.Replace(s.Key.ToString(), s);
                }
            }
        }

        /// <summary>
        /// scatter2D删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void miScatter2DPointDelete_Click(object sender, EventArgs e)
        {
            ScatterPointLayer spl = this._gisManager.InteractiveSystem.CurrentLayer as ScatterPointLayer;

            if (spl == null || spl.Parent == null)
            {
                return;
            }

            ProjectService.DefaultService.Project.Scatter2dData.GetDataById(spl.Id).RemovePoint(spl.SelectedShapeIds);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void miConceptLayerNone_Click(object sender, EventArgs e)
        {

        }

        #endregion




        static GisModule defaultModule;

        public static GisModule DefaultModule
        {
            get
            {

                if (defaultModule == null)
                {
                    defaultModule = new GisModule();

                }

                return defaultModule;
            }

        }

        GisManager _gisManager;

        public GisManager GisManager
        {
            get { return _gisManager; }

        }


        Map _defaultMap;

        #region gis中固定的LayerId


        /// <summary>
        /// 向量图层id
        /// </summary>
        public readonly string VectorLayerID = "vector";

        /// <summary>
        /// 等值线Id
        /// </summary>
        public readonly string IsolineLayerId = "Isoline";

        /// <summary>
        /// 网格所属组的Id
        /// </summary>
        public readonly string GridGroupLayerId = "GridGroup";

        /// <summary>
        /// 网格Id
        /// </summary>
        public readonly string GridLayerId = "Grid";

        public readonly string BarrierLayerId = "Barrier";

        /// <summary>
        /// 离散点集合固定Id
        /// </summary>
        public readonly string Scatter2DGroupLayerId = "ScatterPointGroup";

        /// <summary>
        /// ModFlow默认Id
        /// </summary>
        public readonly string ModFlowLayerId = "ModFlow";

        /// <summary>
        /// 网格框架Id
        /// </summary>
        public readonly string GridFrameLayerId = "GridFrame";


        #region 源汇项图层Id

        public readonly string RiverLayerId = "RIVER";

        public readonly string WellLayerId = "WELL";

        public readonly string GHBLayerId = "GHB";

        public readonly string DrainLayerId = "Drain";

        public readonly string SpecifiedHeadLayerId = "SPECIFIEDHEAD";

        public readonly string IBoundLayerId = "IBound";

        #endregion

        #region 概念图层图形表现样式Id

        public readonly string displayBarrierStyleKey = "barrier";

        public readonly string displayDrainStyleKey = "drain";

        public readonly string displayGeneralHeadStyleKey = "generalhead";

        public readonly string displayIBoundStyleKey = "ibound";

        public readonly string displayMassLoadStyleKey = "massload";

        public readonly string displayDefaultStyleKey = "default";

        public readonly string displayRiverStyleKey = "river";

        public readonly string displaySeepageStyleKey = "seepage";

        public readonly string displaySpecifiedConcStyleKey = "specifiedconc";

        public readonly string displaySpecifiedFlowStyleKey = "specifiedflow";

        public readonly string displaySpecifiedHeadStyleKey = "specifiedhead";

        public readonly string displayWellStyleKey = "well";


        #endregion


        #endregion


        #region 公共属性

        public Map DefaultMap
        {
            get { return _defaultMap; }
            set
            {
                _defaultMap = value;

                this._gisManager.CurrentMap = _defaultMap;
                this._gisManager.CurrentMap.MouseMove += new MouseEventHandler(CurrentMap_MouseMove);

                //    //测试重绘

                //this._defaultMap.Refresh();

                //    //测试用代码

                //this.BuildDefaultLayer();

            }
        }




        #endregion

        #region 流程部分,事件部分

        public void DefaultService_ProjChanged(HAUtil.ProjChangedType chType)
        {

            ///刷新界面显示

            switch (chType)
            {
                case HAUtil.ProjChangedType.NEW:

                    _gisManager.NewProj(ProjectService.DefaultService.GetProjPath(ProjPath.WORKPATH));

                    this.BuildDefaultLayer();

                    break;
                case HAUtil.ProjChangedType.SAVE:

                    _gisManager.SaveProj();

                    break;
                case HAUtil.ProjChangedType.CLOSE:

                    _gisManager.CloseProj();
                    this._defaultMap.BackColor = System.Drawing.Color.White;

                    break;
                case HAUtil.ProjChangedType.OPEN:

                    _gisManager.OpenProj(ProjectService.DefaultService.GetProjPath(ProjPath.WORKPATH));
                    this._defaultMap.BackColor = ProjectService.DefaultService.Project.DisplayOption2.BackColor;
                    this._defaultMap.ViewExtents = this.DefaultMap.ViewExtents;

                    break;
                default:
                    break;
            }






        }


        public void DefaultService_UIUpdatting(object sender, ProjectUIEventArgs e)
        {
            try
            {
                this.DefaultMap.Layers.SuspendEvents();

                switch (e.Type)
                {
                    case UIREFRESHTYPE.ALL:
                        break;
                    case UIREFRESHTYPE.WATERGRIDMODIFIED:
                        WaterGridModifiedEventArgs args = (WaterGridModifiedEventArgs)e.Param;
                        switch (args.Type)
                        {
                            case WaterGridModifiedType.IBOUND:

                                this.OnBoundsChanged();

                                break;
                            case WaterGridModifiedType.INITHEAD:


                                break;
                            case WaterGridModifiedType.CONFIEDELEVATION:
                                break;
                            case WaterGridModifiedType.CONFIEDLAYER:
                                break;
                            default:
                                break;
                        }


                        break;
                    case UIREFRESHTYPE.GRIDMODIDIFIED:

                        GridModifiedEventArgs gArgs = (GridModifiedEventArgs)e.Param;
                        switch (gArgs.Type)
                        {
                            case GridModifiedType.ELEVATION:
                                break;
                            case GridModifiedType.ROWCOORDS:
                                break;
                            case GridModifiedType.COLCOORDS:
                                break;
                            case GridModifiedType.CROSSPOINTMOVE:
                                //更改在OnGridChanged中触发在此无需操作 保改                         

                                break;
                            default:
                                break;
                        }


                        this.OnGridChanged();

                        break;
                    case UIREFRESHTYPE.GRIDRESET:

                        this.OnResetGrid((CollecionChangedEventArgs)e.Param);

                        break;

                    case UIREFRESHTYPE.SCCOLLECION:

                        this.OnSCCollectionChanged((SCColleconChangedEventArgs)e.Param);


                        break;

                    //位图部分相关
                    case UIREFRESHTYPE.BitImageCollectionChanged:

                        this.OnBitImageCollectionChanged((BitImageCollectionChangedEventArgs)e.Param);

                        break;



                    //mapdata部分的相关操作

                    //当是gridframe modified
                    case UIREFRESHTYPE.GRIDFRAMEMODIFIED:

                        this.OnModifiedGridFrame((ObjectOperationEventArgs)e.Param);

                        break;


                    case UIREFRESHTYPE.FOCHANGED:

                        this.OnFOChanged((FOCollecionChangedEventArgs)e.Param);

                        break;

                    //case UIREFRESHTYPE.ContourlineChanged:

                    //    OnCurrentDataSetChanged();

                    //    break;

                    case  UIREFRESHTYPE.ContourlineChanged2 :  //刘加，新的等值线改变事件

                        this.OnContourLineChanged(e);

                        break;

                    case UIREFRESHTYPE.CURRENTDATASETCHANGED:

                        OnCurrentDataSetChanged();

                        break;

                    case UIREFRESHTYPE.CURRENTFLOWVECTORDATACHANGED:
                        //刘加。向量图层 

                        this.OnVectorLayerChanged();

                        break;

                    case UIREFRESHTYPE.VectorsSetupChanged :
                        //向量图层参数改变时，刘加
                        this.OnVectorParaChanged();
                        break;

                    case UIREFRESHTYPE.CoverageCollecionChanged:

                        this.OnCoverageCollecionChanged((CoverageCollectionChangedEventArgs)e.Param);

                        break;

                    case UIREFRESHTYPE.ModflowCollecionChanged:

                        this.OnModflowCollecionChanged((CollecionChangedEventArgs)e.Param);

                        break;

                    case UIREFRESHTYPE.MODFLOWChanged:

                        this.OnMODFLOWChanged((ModelChangedEventArgs)e.Param);

                        break;

                    case UIREFRESHTYPE.SCATTER2DCOLLECTION:

                        this.OnScatter2DCollectionChanged((CollecionChangedEventArgs)e.Param);

                        break;

                    case UIREFRESHTYPE.SCATTER2DSHAPE:

                        this.OnScatter2DShapeChanged((Scatter2DPointsChangedEventArgs)e.Param);

                        break;

                    case UIREFRESHTYPE.DISPLAYOPTIONS:

                        #region 具体操作 废弃

                        //DisplayOption displayOption = ProjectSerivce.DefaultService.Project.DisplayOption;
                        //DisplayOptionsChangedEventArgs disArgs = (DisplayOptionsChangedEventArgs)e.Param;

                        /////操作非必须，但考虑效率，方便概念层更改加在此处
                        //VectorLayer vl = null;

                        //List<VectorLayer> vls = new List<VectorLayer>();
                        //List<string> conceptLayerIds = new List<string>();
                        //foreach (ConceptualModel cm in ProjectSerivce.DefaultService.Project.MapData.ConceptualModelCL)
                        //{
                        //    foreach (Coverage c in cm.Coverages)
                        //    {
                        //        conceptLayerIds.Add(c.Key.ToString());
                        //        if(( vl = (VectorLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(c.Key.ToString()))!=null)
                        //        {
                        //            vls.Add(vl);
                        //        }
                        //    }
                        //}


                        //foreach (string property in disArgs.PropNames)
                        //{
                        //    switch (disArgs.Type)
                        //    {
                        //        case DisplayOptionsType.Grid3D:

                        //            #region Grid3D表现更改触发


                        //            switch ((DOGrid3dType)Enum.Parse(typeof(DOGrid3dType), property))
                        //            {
                        //                case DOGrid3dType.IsShowContour:
                        //                    break;
                        //                case DOGrid3dType.IsShowVector:
                        //                    break;
                        //                default:
                        //                    break;
                        //            }

                        //            #endregion

                        //            break;
                        //        case DisplayOptionsType.ModFlow:

                        //            #region ModFlow表现更改触发
                        //            BarrierLayer barrierLayer=null;
                        //            GridSourceSinksLayer gssLayer = null;
                        //            HA.Data.DOModFlow modflow = displayOption.Modflow;

                        //            switch (property)
                        //            {
                        //                case "ConstantHead":

                        //                    gssLayer = (GridSourceSinksLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(IBoundLayerId);
                        //                    if (gssLayer == null)
                        //                        return;
                        //                    gssLayer.SetFeatureDisplayStyle(DisplayTypeConverter(modflow.ConstantHead.DisplayShape), modflow.ConstantHead.Color, modflow.ConstantHead.Size);
                        //                    gssLayer.DisplayOptionVisible = modflow.ConstantHead.Enabled;

                        //                    break;

                        //                case "Drains":

                        //                    gssLayer = (GridSourceSinksLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(DrainLayerId);
                        //                    if (gssLayer == null)
                        //                        return;
                        //                    gssLayer.SetFeatureDisplayStyle(DisplayTypeConverter(modflow.Drains.DisplayShape), modflow.Drains.Color, modflow.Drains.Size);
                        //                    gssLayer.DisplayOptionVisible = modflow.Drains.Enabled;

                        //                    break;

                        //                case "DryCell":

                        //                    break;

                        //                case "GeneralHead":

                        //                    gssLayer = (GridSourceSinksLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(GHBLayerId);
                        //                    if (gssLayer == null)
                        //                        return;
                        //                    gssLayer.SetFeatureDisplayStyle(DisplayTypeConverter(modflow.GeneralHead.DisplayShape), modflow.GeneralHead.Color, modflow.GeneralHead.Size);
                        //                    gssLayer.DisplayOptionVisible = modflow.GeneralHead.Enabled;

                        //                    break;

                        //                case "HorizFlowBarrier":
                        //                    barrierLayer = (BarrierLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(BarrierLayerId);
                        //                    if (barrierLayer == null)
                        //                        return;
                        //                    barrierLayer.Color = modflow.HorizFlowBarrier.Color;
                        //                    barrierLayer.DisplayOptionVisible = modflow.HorizFlowBarrier.Enabled;

                        //                    break;

                        //                case "MarkFloodedCell":

                        //                    break;

                        //                case "Rivers":

                        //                    gssLayer = (GridSourceSinksLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(RiverLayerId);
                        //                    if (gssLayer == null)
                        //                        return;
                        //                    gssLayer.SetFeatureDisplayStyle(DisplayTypeConverter(modflow.Rivers.DisplayShape), modflow.Rivers.Color, modflow.Rivers.Size);
                        //                    gssLayer.DisplayOptionVisible = modflow.Rivers.Enabled;

                        //                    break;

                        //                case "TransientData":

                        //                    gssLayer = (GridSourceSinksLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(SpecifiedHeadLayerId);
                        //                    if (gssLayer == null)
                        //                        return;
                        //                    gssLayer.SetFeatureDisplayStyle(DisplayTypeConverter(modflow.TransientData.DisplayShape), modflow.TransientData.Color, modflow.TransientData.Size);
                        //                    gssLayer.DisplayOptionVisible = modflow.TransientData.Enabled;

                        //                    break;

                        //                case "WaterTable":

                        //                    break;

                        //                case "Wells":

                        //                    gssLayer = (GridSourceSinksLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(WellLayerId);
                        //                    if (gssLayer == null)
                        //                        return;
                        //                    gssLayer.SetFeatureDisplayStyle(DisplayTypeConverter(modflow.Wells.DisplayShape), modflow.Wells.Color, modflow.Wells.Size);
                        //                    gssLayer.DisplayOptionVisible = modflow.Wells.Enabled;

                        //                    break;

                        //                default:
                        //                    break;
                        //            }
                        //            if (gssLayer != null)
                        //                gssLayer.ILayer.Invalidate();
                        //            if (barrierLayer != null)
                        //            {
                        //                if (barrierLayer.LnLayer.DataSet.Features.Count > 0)
                        //                    barrierLayer.LnLayer.Invalidate();
                        //                if (barrierLayer.PyLayer.DataSet.Features.Count > 0)
                        //                    barrierLayer.PyLayer.Invalidate();
                        //            }
                        //            # endregion

                        //            break;
                        //        case DisplayOptionsType.Particles:

                        //            #region Particles表现更改触发

                        //            switch (property)
                        //            {
                        //                default:
                        //                    break;
                        //            }

                        //            # endregion

                        //            break;
                        //        case DisplayOptionsType.MapData:

                        //            #region MapData表现更改触发


                        //            HA.Data.DOMap mapData = displayOption.Map;

                        //            switch (property)
                        //            {
                        //                case "Barrier":

                        //                    foreach (VectorLayer item in vls)
                        //                    {
                        //                        if (!item.ShapeStyleAndIdStorage.ContainsKey(displayBarrierStyleKey))
                        //                            continue;
                        //                        item.ShapeStyleAndIdStorage[displayBarrierStyleKey].Color = mapData.Barrier.Color;
                        //                        item.ShapeStyleAndIdStorage[displayBarrierStyleKey].PointSize = mapData.Barrier.Size;
                        //                        item.ShapeStyleAndIdStorage[displayBarrierStyleKey].PointShape = DisplayTypeConverterForGisMode(mapData.Barrier.DisplayShape);
                        //                    }

                        //                    break;

                        //                case "Drain":

                        //                    foreach (VectorLayer item in vls)
                        //                    {
                        //                        if (!item.ShapeStyleAndIdStorage.ContainsKey(displayDrainStyleKey))
                        //                            continue;
                        //                        item.ShapeStyleAndIdStorage[displayDrainStyleKey].Color = mapData.Drain.Color;
                        //                        item.ShapeStyleAndIdStorage[displayDrainStyleKey].PointSize = mapData.Drain.Size;
                        //                        item.ShapeStyleAndIdStorage[displayDrainStyleKey].PointShape = DisplayTypeConverterForGisMode(mapData.Drain.DisplayShape);
                        //                    }

                        //                    break;

                        //                case "GeneralHead":

                        //                    foreach (VectorLayer item in vls)
                        //                    {
                        //                        if (!item.ShapeStyleAndIdStorage.ContainsKey(displayGeneralHeadStyleKey))
                        //                            continue;
                        //                        item.ShapeStyleAndIdStorage[displayGeneralHeadStyleKey].Color = mapData.GeneralHead.Color;
                        //                        item.ShapeStyleAndIdStorage[displayGeneralHeadStyleKey].PointSize = mapData.GeneralHead.Size;
                        //                        item.ShapeStyleAndIdStorage[displayGeneralHeadStyleKey].PointShape = DisplayTypeConverterForGisMode(mapData.GeneralHead.DisplayShape);
                        //                    }

                        //                    break;

                        //                case "IBound":

                        //                    foreach (VectorLayer item in vls)
                        //                    {
                        //                        if (!item.ShapeStyleAndIdStorage.ContainsKey(displayIBoundStyleKey))
                        //                            continue;
                        //                        item.ShapeStyleAndIdStorage[displayIBoundStyleKey].Color = mapData.IBound.Color;
                        //                        item.ShapeStyleAndIdStorage[displayIBoundStyleKey].PointSize = mapData.IBound.Size;
                        //                        item.ShapeStyleAndIdStorage[displayIBoundStyleKey].PointShape = DisplayTypeConverterForGisMode(mapData.IBound.DisplayShape);
                        //                    }

                        //                    break;

                        //                case "MassLoad":

                        //                    foreach (VectorLayer item in vls)
                        //                    {
                        //                        if (!item.ShapeStyleAndIdStorage.ContainsKey(displayMassLoadStyleKey))
                        //                            continue;
                        //                        item.ShapeStyleAndIdStorage[displayMassLoadStyleKey].Color = mapData.MassLoad.Color;
                        //                        item.ShapeStyleAndIdStorage[displayMassLoadStyleKey].PointSize = mapData.MassLoad.Size;
                        //                        item.ShapeStyleAndIdStorage[displayMassLoadStyleKey].PointShape = DisplayTypeConverterForGisMode(mapData.MassLoad.DisplayShape);
                        //                    }

                        //                    break;

                        //                case "Default" :

                        //                    foreach (VectorLayer item in vls)
                        //                    {
                        //                        if (!item.ShapeStyleAndIdStorage.ContainsKey(displayDefaultStyleKey))
                        //                            continue;
                        //                        //item.ShapeStyleAndIdStorage[displayDefaultStyleKey].Color = mapData.MassLoad.Color;
                        //                        //item.ShapeStyleAndIdStorage[displayDefaultStyleKey].PointSize = mapData.MassLoad.Size;
                        //                        //item.ShapeStyleAndIdStorage[displayDefaultStyleKey].PointShape = DisplayTypeConverterForGisMode(mapData.MassLoad.DisplayShape);
                        //                    }

                        //                    break;

                        //                case "River":

                        //                    foreach (VectorLayer item in vls)
                        //                    {
                        //                        if (!item.ShapeStyleAndIdStorage.ContainsKey(displayRiverStyleKey))
                        //                            continue;
                        //                        item.ShapeStyleAndIdStorage[displayRiverStyleKey].Color = mapData.River.Color;
                        //                        item.ShapeStyleAndIdStorage[displayRiverStyleKey].PointSize = mapData.River.Size;
                        //                        item.ShapeStyleAndIdStorage[displayRiverStyleKey].PointShape = DisplayTypeConverterForGisMode(mapData.River.DisplayShape);
                        //                    }

                        //                    break;

                        //                case "Seepage":

                        //                    foreach (VectorLayer item in vls)
                        //                    {
                        //                        if (!item.ShapeStyleAndIdStorage.ContainsKey(displaySeepageStyleKey))
                        //                            continue;
                        //                        item.ShapeStyleAndIdStorage[displaySeepageStyleKey].Color = mapData.Seepage.Color;
                        //                        item.ShapeStyleAndIdStorage[displaySeepageStyleKey].PointSize = mapData.Seepage.Size;
                        //                        item.ShapeStyleAndIdStorage[displaySeepageStyleKey].PointShape = DisplayTypeConverterForGisMode(mapData.Seepage.DisplayShape);
                        //                    }

                        //                    break;

                        //                case "SpecifiedConc":

                        //                    foreach (VectorLayer item in vls)
                        //                    {
                        //                        if (!item.ShapeStyleAndIdStorage.ContainsKey(displaySpecifiedConcStyleKey))
                        //                            continue;
                        //                        item.ShapeStyleAndIdStorage[displaySpecifiedConcStyleKey].Color = mapData.SpecifiedConc.Color;
                        //                        item.ShapeStyleAndIdStorage[displaySpecifiedConcStyleKey].PointSize = mapData.SpecifiedConc.Size;
                        //                        item.ShapeStyleAndIdStorage[displaySpecifiedConcStyleKey].PointShape = DisplayTypeConverterForGisMode(mapData.SpecifiedConc.DisplayShape);
                        //                    }

                        //                    break;

                        //                case "SpecifiedFlow":

                        //                    foreach (VectorLayer item in vls)
                        //                    {
                        //                        if (!item.ShapeStyleAndIdStorage.ContainsKey(displaySpecifiedFlowStyleKey))
                        //                            continue;
                        //                        item.ShapeStyleAndIdStorage[displaySpecifiedFlowStyleKey].Color = mapData.SpecifiedFlow.Color;
                        //                        item.ShapeStyleAndIdStorage[displaySpecifiedFlowStyleKey].PointSize = mapData.SpecifiedFlow.Size;
                        //                        item.ShapeStyleAndIdStorage[displaySpecifiedFlowStyleKey].PointShape = DisplayTypeConverterForGisMode(mapData.SpecifiedFlow.DisplayShape);
                        //                    }

                        //                    break;

                        //                case "SpecifiedHead":

                        //                    foreach (VectorLayer item in vls)
                        //                    {
                        //                        if (!item.ShapeStyleAndIdStorage.ContainsKey(displaySpecifiedHeadStyleKey))
                        //                            continue;
                        //                        item.ShapeStyleAndIdStorage[displaySpecifiedHeadStyleKey].Color = mapData.SpecifiedHead.Color;
                        //                        item.ShapeStyleAndIdStorage[displaySpecifiedHeadStyleKey].PointSize = mapData.SpecifiedHead.Size;
                        //                        item.ShapeStyleAndIdStorage[displaySpecifiedHeadStyleKey].PointShape = DisplayTypeConverterForGisMode(mapData.SpecifiedHead.DisplayShape);
                        //                    }

                        //                    break;

                        //                case "Well":

                        //                    foreach (VectorLayer item in vls)
                        //                    {
                        //                        if (!item.ShapeStyleAndIdStorage.ContainsKey(displayWellStyleKey))
                        //                            continue;
                        //                        item.ShapeStyleAndIdStorage[displayWellStyleKey].Color = mapData.Well.Color;
                        //                        item.ShapeStyleAndIdStorage[displayWellStyleKey].PointSize = mapData.Well.Size;
                        //                        item.ShapeStyleAndIdStorage[displayWellStyleKey].PointShape = DisplayTypeConverterForGisMode(mapData.Well.DisplayShape);
                        //                    }

                        //                    break;

                        //                default:
                        //                    break;
                        //            }

                        //            foreach (VectorLayer vlayer in vls)
                        //            {
                        //                vlayer.PtLayer.Invalidate();
                        //                vlayer.LnLayer.Invalidate();
                        //                vlayer.PyLayer.Invalidate();
                        //            }

                        //            # endregion

                        //            break;
                        //        case DisplayOptionsType.Common:

                        //            #region 公共表现更改触发

                        //            switch (property)
                        //            {
                        //                case "BackColor":

                        //                    this._defaultMap.BackColor = displayOption.BackColor;
                        //                    this._defaultMap.ViewExtents = this.DefaultMap.ViewExtents;

                        //                    break;

                        //                case "ZMagnification":

                        //                    this.OnGridChanged();

                        //                    break;

                        //                default:
                        //                    break;
                        //            }

                        //            # endregion

                        //            break;
                        //        default:
                        //            break;
                        //    }
                        //}


                        #endregion

                        break;

                    case UIREFRESHTYPE.DISPLAYOPTIONS2:
                         #region 具体操作
                        
                        DisplayOption2 displayOption2 = ProjectService.DefaultService.Project.DisplayOption2;
                        DisplayOptionsChangedEventArgs disArgs2 = (DisplayOptionsChangedEventArgs)e.Param;

                        ///操作非必须，但考虑效率，方便概念层更改加在此处
                        VectorLayer vl2 = null;

                        List<VectorLayer> vls2 = new List<VectorLayer>();
                        List<string> conceptLayerIds2 = new List<string>();
                        foreach (ConceptualModel cm in ProjectService.DefaultService.Project.MapData.ConceptualModelCL)
                        {
                            foreach (Coverage c in cm.Coverages)
                            {
                                conceptLayerIds2.Add(c.Key.ToString());
                                if(( vl2 = (VectorLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(c.Key.ToString()))!=null)
                                {
                                    vls2.Add(vl2);
                                }
                            }
                        }


                        foreach (string property in disArgs2.PropNames)
                        {
                            switch (disArgs2.Type)
                            {
                                case DisplayOptionsType.Grid3D:

                                    #region Grid3D表现更改触发


                                    switch ((DOGrid3dType)Enum.Parse(typeof(DOGrid3dType), property))
                                    {
                                        case DOGrid3dType.IsShowContour:

                                            IsolineLayer isoline = (IsolineLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(IsolineLayerId);
                                            if (isoline == null)
                                                return;
                                            isoline.Visible = displayOption2.DoGrid3dData.Grid3d.IsShowContour;

                                            isoline.ILayer.Invalidate();

                                            break;
                                        case DOGrid3dType.IsShowVector:

                                            FlowVectorLayer flowVector = (FlowVectorLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(VectorLayerID);
                                            if (flowVector == null)
                                                return;
                                            flowVector.Visible = displayOption2.DoGrid3dData.Grid3d.IsShowVector;

                                            flowVector.ILayer.Invalidate();

                                            break;
                                        default:
                                            break;
                                    }

                                    #endregion

                                    break;
                                case DisplayOptionsType.ModFlow:

                                    #region ModFlow表现更改触发
                                    BarrierLayer barrierLayer=null;
                                    GridSourceSinksLayer gssLayer = null;
                                    HA.Data.DisplayOptions2.DOModFlow modflow = displayOption2.DoGrid3dData.Modflow;

                                    switch (property)
                                    {
                                        case "ConstantHead":

                                            gssLayer = (GridSourceSinksLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(IBoundLayerId);
                                            if (gssLayer == null)
                                                return;
                                            gssLayer.SetFeatureDisplayStyle(DisplayTypeConverter(modflow.ConstantHead.DisplayShape), modflow.ConstantHead.Color, modflow.ConstantHead.Size);
                                            gssLayer.DisplayOptionVisible = modflow.ConstantHead.Enabled;

                                            break;

                                        case "Drains":

                                            gssLayer = (GridSourceSinksLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(DrainLayerId);
                                            if (gssLayer == null)
                                                return;
                                            gssLayer.SetFeatureDisplayStyle(DisplayTypeConverter(modflow.Drains.DisplayShape), modflow.Drains.Color, modflow.Drains.Size);
                                            gssLayer.DisplayOptionVisible = modflow.Drains.Enabled;

                                            break;

                                        case "DryCell":

                                            break;

                                        case "GeneralHead":

                                            gssLayer = (GridSourceSinksLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(GHBLayerId);
                                            if (gssLayer == null)
                                                return;
                                            gssLayer.SetFeatureDisplayStyle(DisplayTypeConverter(modflow.GeneralHead.DisplayShape), modflow.GeneralHead.Color, modflow.GeneralHead.Size);
                                            gssLayer.DisplayOptionVisible = modflow.GeneralHead.Enabled;

                                            break;

                                        case "HorizFlowBarrier":
                                            barrierLayer = (BarrierLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(BarrierLayerId);
                                            if (barrierLayer == null)
                                                return;
                                            barrierLayer.Color = modflow.HorizFlowBarrier.Color;
                                            barrierLayer.DisplayOptionVisible = modflow.HorizFlowBarrier.Enabled;

                                            break;

                                        case "MarkFloodedCell":

                                            break;

                                        case "Rivers":

                                            gssLayer = (GridSourceSinksLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(RiverLayerId);
                                            if (gssLayer == null)
                                                return;
                                            gssLayer.SetFeatureDisplayStyle(DisplayTypeConverter(modflow.Rivers.DisplayShape), modflow.Rivers.Color, modflow.Rivers.Size);
                                            gssLayer.DisplayOptionVisible = modflow.Rivers.Enabled;

                                            break;

                                        case "TransientData":

                                            gssLayer = (GridSourceSinksLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(SpecifiedHeadLayerId);
                                            if (gssLayer == null)
                                                return;
                                            gssLayer.SetFeatureDisplayStyle(DisplayTypeConverter(modflow.TransientData.DisplayShape), modflow.TransientData.Color, modflow.TransientData.Size);
                                            gssLayer.DisplayOptionVisible = modflow.TransientData.Enabled;

                                            break;

                                        case "WaterTable":

                                            break;

                                        case "Wells":

                                            gssLayer = (GridSourceSinksLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(WellLayerId);
                                            if (gssLayer == null)
                                                return;
                                            gssLayer.SetFeatureDisplayStyle(DisplayTypeConverter(modflow.Wells.DisplayShape), modflow.Wells.Color, modflow.Wells.Size);
                                            gssLayer.DisplayOptionVisible = modflow.Wells.Enabled;

                                            break;

                                        default:
                                            break;
                                    }
                                    if (gssLayer != null)
                                        gssLayer.ILayer.Invalidate();
                                    if (barrierLayer != null)
                                    {
                                        if (barrierLayer.LnLayer.DataSet.Features.Count > 0)
                                            barrierLayer.LnLayer.Invalidate();
                                        if (barrierLayer.PyLayer.DataSet.Features.Count > 0)
                                            barrierLayer.PyLayer.Invalidate();
                                    }
                                    # endregion

                                    break;
                                case DisplayOptionsType.Particles:

                                    #region Particles表现更改触发

                                    switch (property)
                                    {
                                        default:
                                            break;
                                    }

                                    # endregion

                                    break;
                                case DisplayOptionsType.MapData:

                                    #region MapData表现更改触发


                                    HA.Data.DisplayOptions2.DOMap mapData = displayOption2.DoMapData.Map;

                                    switch (property)
                                    {
                                        case "Barrier":

                                            foreach (VectorLayer item in vls2)
                                            {
                                                if (!item.ShapeStyleAndIdStorage.ContainsKey(displayBarrierStyleKey))
                                                    continue;
                                                item.ShapeStyleAndIdStorage[displayBarrierStyleKey].Color = mapData.Barrier.Color;
                                                item.ShapeStyleAndIdStorage[displayBarrierStyleKey].PointSize = mapData.Barrier.Size;
                                                item.ShapeStyleAndIdStorage[displayBarrierStyleKey].PointShape = DisplayTypeConverterForGisMode(mapData.Barrier.DisplayShape);
                                            }

                                            break;

                                        case "Drain":

                                            foreach (VectorLayer item in vls2)
                                            {
                                                if (!item.ShapeStyleAndIdStorage.ContainsKey(displayDrainStyleKey))
                                                    continue;
                                                item.ShapeStyleAndIdStorage[displayDrainStyleKey].Color = mapData.Drain.Color;
                                                item.ShapeStyleAndIdStorage[displayDrainStyleKey].PointSize = mapData.Drain.Size;
                                                item.ShapeStyleAndIdStorage[displayDrainStyleKey].PointShape = DisplayTypeConverterForGisMode(mapData.Drain.DisplayShape);
                                            }

                                            break;

                                        case "GeneralHead":

                                            foreach (VectorLayer item in vls2)
                                            {
                                                if (!item.ShapeStyleAndIdStorage.ContainsKey(displayGeneralHeadStyleKey))
                                                    continue;
                                                item.ShapeStyleAndIdStorage[displayGeneralHeadStyleKey].Color = mapData.GeneralHead.Color;
                                                item.ShapeStyleAndIdStorage[displayGeneralHeadStyleKey].PointSize = mapData.GeneralHead.Size;
                                                item.ShapeStyleAndIdStorage[displayGeneralHeadStyleKey].PointShape = DisplayTypeConverterForGisMode(mapData.GeneralHead.DisplayShape);
                                            }

                                            break;

                                        case "IBound":

                                            foreach (VectorLayer item in vls2)
                                            {
                                                if (!item.ShapeStyleAndIdStorage.ContainsKey(displayIBoundStyleKey))
                                                    continue;
                                                item.ShapeStyleAndIdStorage[displayIBoundStyleKey].Color = mapData.IBound.Color;
                                                item.ShapeStyleAndIdStorage[displayIBoundStyleKey].PointSize = mapData.IBound.Size;
                                                item.ShapeStyleAndIdStorage[displayIBoundStyleKey].PointShape = DisplayTypeConverterForGisMode(mapData.IBound.DisplayShape);
                                            }

                                            break;

                                        case "MassLoad":

                                            foreach (VectorLayer item in vls2)
                                            {
                                                if (!item.ShapeStyleAndIdStorage.ContainsKey(displayMassLoadStyleKey))
                                                    continue;
                                                item.ShapeStyleAndIdStorage[displayMassLoadStyleKey].Color = mapData.MassLoad.Color;
                                                item.ShapeStyleAndIdStorage[displayMassLoadStyleKey].PointSize = mapData.MassLoad.Size;
                                                item.ShapeStyleAndIdStorage[displayMassLoadStyleKey].PointShape = DisplayTypeConverterForGisMode(mapData.MassLoad.DisplayShape);
                                            }

                                            break;

                                        case "Default" :

                                            foreach (VectorLayer item in vls2)
                                            {
                                                if (!item.ShapeStyleAndIdStorage.ContainsKey(displayDefaultStyleKey))
                                                    continue;
                                                //item.ShapeStyleAndIdStorage[displayDefaultStyleKey].Color = mapData.MassLoad.Color;
                                                //item.ShapeStyleAndIdStorage[displayDefaultStyleKey].PointSize = mapData.MassLoad.Size;
                                                //item.ShapeStyleAndIdStorage[displayDefaultStyleKey].PointShape = DisplayTypeConverterForGisMode(mapData.MassLoad.DisplayShape);
                                            }

                                            break;

                                        case "River":

                                            foreach (VectorLayer item in vls2)
                                            {
                                                if (!item.ShapeStyleAndIdStorage.ContainsKey(displayRiverStyleKey))
                                                    continue;
                                                item.ShapeStyleAndIdStorage[displayRiverStyleKey].Color = mapData.River.Color;
                                                item.ShapeStyleAndIdStorage[displayRiverStyleKey].PointSize = mapData.River.Size;
                                                item.ShapeStyleAndIdStorage[displayRiverStyleKey].PointShape = DisplayTypeConverterForGisMode(mapData.River.DisplayShape);
                                            }

                                            break;

                                        case "Seepage":

                                            foreach (VectorLayer item in vls2)
                                            {
                                                if (!item.ShapeStyleAndIdStorage.ContainsKey(displaySeepageStyleKey))
                                                    continue;
                                                item.ShapeStyleAndIdStorage[displaySeepageStyleKey].Color = mapData.Seepage.Color;
                                                item.ShapeStyleAndIdStorage[displaySeepageStyleKey].PointSize = mapData.Seepage.Size;
                                                item.ShapeStyleAndIdStorage[displaySeepageStyleKey].PointShape = DisplayTypeConverterForGisMode(mapData.Seepage.DisplayShape);
                                            }

                                            break;

                                        case "SpecifiedConc":

                                            foreach (VectorLayer item in vls2)
                                            {
                                                if (!item.ShapeStyleAndIdStorage.ContainsKey(displaySpecifiedConcStyleKey))
                                                    continue;
                                                item.ShapeStyleAndIdStorage[displaySpecifiedConcStyleKey].Color = mapData.SpecifiedConc.Color;
                                                item.ShapeStyleAndIdStorage[displaySpecifiedConcStyleKey].PointSize = mapData.SpecifiedConc.Size;
                                                item.ShapeStyleAndIdStorage[displaySpecifiedConcStyleKey].PointShape = DisplayTypeConverterForGisMode(mapData.SpecifiedConc.DisplayShape);
                                            }

                                            break;

                                        case "SpecifiedFlow":

                                            foreach (VectorLayer item in vls2)
                                            {
                                                if (!item.ShapeStyleAndIdStorage.ContainsKey(displaySpecifiedFlowStyleKey))
                                                    continue;
                                                item.ShapeStyleAndIdStorage[displaySpecifiedFlowStyleKey].Color = mapData.SpecifiedFlow.Color;
                                                item.ShapeStyleAndIdStorage[displaySpecifiedFlowStyleKey].PointSize = mapData.SpecifiedFlow.Size;
                                                item.ShapeStyleAndIdStorage[displaySpecifiedFlowStyleKey].PointShape = DisplayTypeConverterForGisMode(mapData.SpecifiedFlow.DisplayShape);
                                            }

                                            break;

                                        case "SpecifiedHead":

                                            foreach (VectorLayer item in vls2)
                                            {
                                                if (!item.ShapeStyleAndIdStorage.ContainsKey(displaySpecifiedHeadStyleKey))
                                                    continue;
                                                item.ShapeStyleAndIdStorage[displaySpecifiedHeadStyleKey].Color = mapData.SpecifiedHead.Color;
                                                item.ShapeStyleAndIdStorage[displaySpecifiedHeadStyleKey].PointSize = mapData.SpecifiedHead.Size;
                                                item.ShapeStyleAndIdStorage[displaySpecifiedHeadStyleKey].PointShape = DisplayTypeConverterForGisMode(mapData.SpecifiedHead.DisplayShape);
                                            }

                                            break;

                                        case "Well":

                                            foreach (VectorLayer item in vls2)
                                            {
                                                if (!item.ShapeStyleAndIdStorage.ContainsKey(displayWellStyleKey))
                                                    continue;
                                                item.ShapeStyleAndIdStorage[displayWellStyleKey].Color = mapData.Well.Color;
                                                item.ShapeStyleAndIdStorage[displayWellStyleKey].PointSize = mapData.Well.Size;
                                                item.ShapeStyleAndIdStorage[displayWellStyleKey].PointShape = DisplayTypeConverterForGisMode(mapData.Well.DisplayShape);
                                            }

                                            break;

                                        default:
                                            break;
                                    }

                                    foreach (VectorLayer vlayer in vls2)
                                    {
                                        vlayer.PtLayer.Invalidate();
                                        vlayer.LnLayer.Invalidate();
                                        vlayer.PyLayer.Invalidate();
                                    }

                                    # endregion

                                    break;
                                case DisplayOptionsType.Common:

                                    #region 公共表现更改触发

                                    switch (property)
                                    {
                                        case "BackColor":

                                            this._defaultMap.BackColor = displayOption2.BackColor;
                                            this._defaultMap.ViewExtents = this.DefaultMap.ViewExtents;

                                            break;

                                        case "ZMagnification":

                                            this.OnGridChanged();
                                            ProjectService.DefaultService.Project.OnCurrentDSChanged();

                                            break;

                                        default:
                                            break;
                                    }

                                    # endregion

                                    break;
                                default:
                                    break;
                            }
                        }

                        
                        #endregion

                        break;

                    case UIREFRESHTYPE.IDWOPTIONChanged:

                        #region 反距离权重参数更改

                        IsolineLayer isolineLayer = (IsolineLayer)_gisManager.LayerSystem.LayerCollection.GetLayer(IsolineLayerId);
                        if (isolineLayer == null) return;
                        isolineLayer.NodalFunctionType = ProjectService.DefaultService.Project.InterpolationOption2D.IdwOption.NodalFunction;
                        isolineLayer.Nq = ProjectService.DefaultService.Project.InterpolationOption2D.IdwOption.Nq;
                        isolineLayer.Nw = ProjectService.DefaultService.Project.InterpolationOption2D.IdwOption.Nw;

                        #endregion

                        break;

                    case UIREFRESHTYPE.KRIGINGOPTIONChanged:

                        #region 克里金插值参数更改



                        #endregion

                        break;

                    default:
                        break;
                }
            }
            catch(Exception ex)
            {
                MessageBox.Show("更新二维绘图出错:"+e.Type.ToString ()+" "+ex.Message);
            }
            finally
            {
                this.DefaultMap.Layers.ResumeEvents();
                //this.DefaultMap.MapFrame.Initialize();
                this.DefaultMap.Invalidate();
            }
        }

        /// <summary>
        /// DisplayShape类型枚举转换为PointShape类型
        /// </summary>
        /// <param name="displayShape"></param>
        /// <returns></returns>
        DotSpatial.Symbology.PointShape DisplayTypeConverterForGisMode(DisplayShape displayShape)
        {
            switch (displayShape)
            {
                case DisplayShape.Diamond:
                    return DotSpatial.Symbology.PointShape.Diamond;
                case DisplayShape.Circle:
                    return DotSpatial.Symbology.PointShape.Ellipse;
                case DisplayShape.Square:
                    return DotSpatial.Symbology.PointShape.Rectangle;
                case DisplayShape.TriangleUp:
                    return DotSpatial.Symbology.PointShape.Triangle;
                //(ptLayer.Symbolizer as PointSymbolizer).Symbols[0].Angle

                case DisplayShape.Line:
                    break;
                case DisplayShape.DottedLine:
                    break;

                default:
                    break;
            }

            return DotSpatial.Symbology.PointShape.Undefined;
        }

        /// <summary>
        /// DisplayShape类型枚举转换为MFSOURCESINKSDISPLAYMODE类型
        /// </summary>
        /// <param name="displayShape"></param>
        /// <returns></returns>
        MFSOURCESINKSDISPLAYMODE DisplayTypeConverter(DisplayShape displayShape)
        {
            switch (displayShape)
            {
                case DisplayShape.Square:
                    return MFSOURCESINKSDISPLAYMODE.Rectangle;

                case DisplayShape.Circle:
                    return MFSOURCESINKSDISPLAYMODE.Ellipse;

                case DisplayShape.Diamond:
                    return MFSOURCESINKSDISPLAYMODE.Diamond;

                case DisplayShape.TriangleUp:
                    return MFSOURCESINKSDISPLAYMODE.Triangle;

                case DisplayShape.Line:
                    break;
                case DisplayShape.DottedLine:
                    break;
                default:
                    break;
            }


            return MFSOURCESINKSDISPLAYMODE.Ellipse;
        }


        void MapData_CollectionChanged(object sender, CollecionChangedEventArgs e)
        {

        }

        void Grid3dData_CollectionChanged(object sender, CollecionChangedEventArgs e)
        {
            Grid3d gd = (Grid3d)e.Child;

            switch (e.Type)
            {
                case CollectionChangedType.ADD:

                    break;
                case CollectionChangedType.REMOVE:
                    break;
                case CollectionChangedType.MOVE:
                    break;
                case CollectionChangedType.REPLACE:
                    break;
                case CollectionChangedType.RESET:
                    break;
                default:
                    break;
            }
        }

        #endregion

        #region 受保护的方法

        protected void OnScatter2DCollectionChanged(CollecionChangedEventArgs args)
        {
            Scatter2D scatter2D = (Scatter2D)args.Child;
            GroupLayer gl = (GroupLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(Scatter2DGroupLayerId);
            if (gl == null)
                return;
            ScatterPointLayer spl = null;
            List<ScatterPointShape> spss;

            switch (args.Type)
            {
                case CollectionChangedType.ADD:

                    spl = new ScatterPointLayer(scatter2D.Key.ToString(), this._gisManager.VIEWMODE, null);
                    ScatterPointShape sps = null;
                    spss = new List<ScatterPointShape>();
                    foreach (ScatterPoint sp in scatter2D.DataSet)
                    {
                        sps = new ScatterPointShape(sp.Id, new Coordinate(sp.X, sp.Y, sp.Z), sp.Values);
                        spss.Add(sps);
                    }

                    spl.ScatterShps = spss;
                    
                    gl.AddChild(spl);
                    this._gisManager.ZoomToCurrentLayer(spl.Id);

                    break;
                case CollectionChangedType.REMOVE:

                    if (gl.Childs.Contains(this._gisManager.InteractiveSystem.CurrentLayer))
                        this._gisManager.InteractiveSystem.CurrentLayer = null;

                    gl.RemoveChild(scatter2D.Key.ToString());

                    break;
                case CollectionChangedType.MOVE:
                    break;
                case CollectionChangedType.REPLACE:
                    spss = new List<ScatterPointShape>();
                    spl = (ScatterPointLayer)gl.GetChild(scatter2D.Key.ToString());
                    foreach (ScatterPoint sp in scatter2D.DataSet)
                    {
                        sps = new ScatterPointShape(sp.Id, new Coordinate(sp.X, sp.Y, sp.Z), sp.Values);
                        spss.Add(sps);
                    }

                    spl.ScatterShps = spss;
                    spl.SelectedShapeIds.Clear();
                    spl.ILayer.Invalidate();

                    break;
                case CollectionChangedType.ITEMEDIT:
                    break;
                case CollectionChangedType.RESET:
                    break;
                case CollectionChangedType.MODIFYDATATYPES:
                    break;
                default:
                    break;
            }
        }

        protected void OnScatter2DShapeChanged(Scatter2DPointsChangedEventArgs args)
        {
            ScatterPointLayer spl = (ScatterPointLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(args.LayerId);
            if (spl == null) return;
            ScatterPointShape spshape = null;

            switch (args.OperationMode)
            {
                case ObjectOperationType.ADD:
                    spshape = new ScatterPointShape(args.ScatterPoint.Id, new Coordinate(args.ScatterPoint.X, args.ScatterPoint.Y), args.ScatterPoint.Values);
                    spl.AddPoint(spshape);
                    break;
                case ObjectOperationType.REMOVE:
                    spl.RemovePoint(args.IdsForDelete);
                    break;
                case ObjectOperationType.MODIFY:
                    spshape = new ScatterPointShape(args.ScatterPoint.Id, new Coordinate(args.ScatterPoint.X, args.ScatterPoint.Y), args.ScatterPoint.Values);
                    spl.EditPoint(spshape);
                    break;
                default:
                    break;
            }

        }

        /// <summary>
        /// ModFlow更改触发的操作
        /// </summary>
        /// <param name="args"></param>
        protected void OnMODFLOWChanged(ModelChangedEventArgs args)
        {
            GroupLayer gl = null;

            //id在Gis中采用固定id

            HyGrid hg;
            DotSpatial.Topology.Coordinate[, ,] coord3D;
            GridSourceSinksLayer gssLayer;
            Project project = ProjectService.DefaultService.Project;
            Grid3d grid3d = project.Grid3dData.MainGrid;
            HA.ModFlow.Domain.DomainLayer.GridData gd;
            gl = (GroupLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(ModFlowLayerId);

            DisplayOption2 displayOption = project.DisplayOption2;
            HA.Data.DisplayOptions2.DOModFlow modFlow = displayOption.DoGrid3dData.Modflow;


            if (gl != null)
            {
                switch (args.ChangedType)
                {
                    case ModelChangedType.CRREATED:
                        if (project.MfData != null)
                        {
                            gd = ProjectService.DefaultService.Project.Grid3dData.MainGrid.ModFlowGrid;
                            coord3D = AlgorithmHelper.ConvertCoordinatesFor2D(grid3d.ModFlowGrid.GetBoundGrid().GridPoints, project.DisplayOption2.ZMagnification);

                            hg = new HyGrid(gd.RowsCount, gd.ColsCount, gd.LayersCount, gd.RowCoords, gd.ColCoords, gd.LayerCoords, gd.OrgX, gd.OrgY, gd.OrgZ, gd.RotationZ, coord3D);


                            List<int[,]> iBounds = grid3d.ModFlowGrid.WaterGrid.GetIBounds();
                            
                            List<int[]> dataIJKs = new List<int[]>();

                            gssLayer = new GridSourceSinksLayer(RiverLayerId, hg, iBounds, dataIJKs, _gisManager.VIEWMODE, project.CurrentViewPort.Number);
                            gssLayer.DisplayOptionVisible = project.DisplayOption2.DoGrid3dData.Modflow.Rivers.Enabled;
                            gl.AddChild(gssLayer);

                            gssLayer.SetFeatureDisplayStyle(DisplayTypeConverter(modFlow.Rivers.DisplayShape), modFlow.Rivers.Color, modFlow.Rivers.Size);

                            gssLayer = new GridSourceSinksLayer(WellLayerId, hg, iBounds, dataIJKs, _gisManager.VIEWMODE, project.CurrentViewPort.Number);
                            gssLayer.DisplayOptionVisible = project.DisplayOption2.DoGrid3dData.Modflow.Wells.Enabled;
                            gl.AddChild(gssLayer);
                            
                            gssLayer.SetFeatureDisplayStyle(DisplayTypeConverter(modFlow.Wells.DisplayShape), modFlow.Wells.Color, modFlow.Wells.Size);

                            gssLayer = new GridSourceSinksLayer(GHBLayerId, hg, iBounds, dataIJKs, _gisManager.VIEWMODE, project.CurrentViewPort.Number);
                            gssLayer.DisplayOptionVisible = project.DisplayOption2.DoGrid3dData.Modflow.GeneralHead.Enabled;
                            gl.AddChild(gssLayer);

                            gssLayer.SetFeatureDisplayStyle(DisplayTypeConverter(modFlow.GeneralHead.DisplayShape), modFlow.GeneralHead.Color, modFlow.GeneralHead.Size);

                            gssLayer = new GridSourceSinksLayer(DrainLayerId, hg, iBounds, dataIJKs, _gisManager.VIEWMODE, project.CurrentViewPort.Number);
                            gssLayer.DisplayOptionVisible = project.DisplayOption2.DoGrid3dData.Modflow.Drains.Enabled;
                            gl.AddChild(gssLayer);
                            gssLayer.SetFeatureDisplayStyle(DisplayTypeConverter(modFlow.Drains.DisplayShape), modFlow.Drains.Color, modFlow.Drains.Size);

                            gssLayer = new GridSourceSinksLayer(SpecifiedHeadLayerId, hg, iBounds, dataIJKs, _gisManager.VIEWMODE, project.CurrentViewPort.Number);
                            gssLayer.DisplayOptionVisible = project.DisplayOption2.DoGrid3dData.Modflow.TransientData.Enabled;
                            gl.AddChild(gssLayer);
                            gssLayer.SetFeatureDisplayStyle(DisplayTypeConverter(modFlow.TransientData.DisplayShape), modFlow.TransientData.Color, modFlow.TransientData.Size);

                            gssLayer = new GridSourceSinksLayer(IBoundLayerId, hg, iBounds, dataIJKs, _gisManager.VIEWMODE, project.CurrentViewPort.Number);
                            gssLayer.DisplayOptionVisible = project.DisplayOption2.DoGrid3dData.Modflow.ConstantHead.Enabled;
                            gl.AddChild(gssLayer);
                            gssLayer.SetFeatureDisplayStyle(DisplayTypeConverter(modFlow.ConstantHead.DisplayShape), modFlow.ConstantHead.Color, modFlow.ConstantHead.Size);


                            //添加barrier图层
                            BarrierLayer barrierLayer = new BarrierLayer(BarrierLayerId, hg, iBounds, project.MfData.HfbData.ToLocationList(), _gisManager.VIEWMODE, project.CurrentViewPort.Number);
                            barrierLayer.DisplayOptionVisible = project.DisplayOption2.DoGrid3dData.Modflow.HorizFlowBarrier.Enabled;
                            gl.AddChild(barrierLayer);
                            barrierLayer.Color = modFlow.HorizFlowBarrier.Color;

                        }
                        break;
                    case ModelChangedType.DELETED:
                        gl = (GroupLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(ModFlowLayerId);

                        if (gl != null)
                        {
                            if (gl.Childs.Contains(this._gisManager.InteractiveSystem.CurrentLayer))
                                this._gisManager.InteractiveSystem.CurrentLayer = null;
                            gl.RemoveAllChild();
                        }

                        break;
                    default:
                        break;
                }
            }
        }

        /// <summary>
        /// 位图集合更改触发的操作
        /// </summary>
        /// <param name="args"></param>
        protected void OnBitImageCollectionChanged(BitImageCollectionChangedEventArgs args)
        {
            string groupLayerId = ProjectService.DefaultService.Project.AssistData.BitImageId;
            GroupLayer gl = (GroupLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(groupLayerId);

            switch (args.Type)
            {
                case CollectionChangedType.ADD:

                    if (gl == null) return;

                    foreach (string item in args.ImageIdAndInfoes.Keys)
                    {
                        string filePath = ProjectService.DefaultService.GetProjPath(ProjPath.RESOURCE) + item;

                        BitImageInfoes bitImageInfo = args.ImageIdAndInfoes[item];

                        ImageLayer imageLayer = new ImageLayer(System.IO.Path.GetFileNameWithoutExtension(item), filePath);
                        imageLayer.SetWorldFile(bitImageInfo.AbsLeftBottomPt, bitImageInfo.AbsRightUpPt, bitImageInfo.Width, bitImageInfo.Height);


                        gl.AddChild(imageLayer);
                        imageLayer.ViewMode = _gisManager.VIEWMODE;
                    }


                    break;
                case CollectionChangedType.REMOVE:

                    if (gl.Childs.Contains(this._gisManager.InteractiveSystem.CurrentLayer))
                        this._gisManager.InteractiveSystem.CurrentLayer = null;

                    foreach (string item in args.DeleteImageIds)
                    {
                        gl.RemoveChild(item);
                    }

                    break;
                case CollectionChangedType.MOVE:
                    break;
                case CollectionChangedType.REPLACE:
                    break;
                case CollectionChangedType.RESET:
                    break;
                default:
                    break;
            }

        }

        /// <summary>
        /// 概念模型中图层更改触发的操作
        /// </summary>
        /// <param name="args"></param>
        protected void OnCoverageCollecionChanged(CoverageCollectionChangedEventArgs args)
        {
            HA.Data.DisplayOptions2.DOMap doMap = ProjectService.DefaultService.Project.DisplayOption2.DoMapData.Map;
            GroupLayer gl = (GroupLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(args.ConcetualModel.Key.ToString());
            if (gl == null)
                return;
            VectorLayer vl = null;

            switch (args.Type)
            {
                case CollectionChangedType.ADD:

                    vl = new VectorLayer(args.Coverage.Key.ToString(),args.Coverage.CoverageType);
                    vl.Desc = args.Coverage.Name;

                    //设置各种类型数据的显示模式
                    vl.ShapeStyleAndIdStorage.Add(displayBarrierStyleKey, new ConceptShapesStorageAndDisplayStyle(doMap.Barrier.Color, doMap.Barrier.Size, DisplayTypeConverterForGisMode(doMap.Barrier.DisplayShape)));
                    vl.ShapeStyleAndIdStorage.Add(displayDrainStyleKey, new ConceptShapesStorageAndDisplayStyle(doMap.Drain.Color, doMap.Drain.Size, DisplayTypeConverterForGisMode(doMap.Drain.DisplayShape)));
                    vl.ShapeStyleAndIdStorage.Add(displayGeneralHeadStyleKey, new ConceptShapesStorageAndDisplayStyle(doMap.GeneralHead.Color, doMap.GeneralHead.Size, DisplayTypeConverterForGisMode(doMap.GeneralHead.DisplayShape)));
                    vl.ShapeStyleAndIdStorage.Add(displayIBoundStyleKey, new ConceptShapesStorageAndDisplayStyle(doMap.IBound.Color, doMap.IBound.Size, DisplayTypeConverterForGisMode(doMap.IBound.DisplayShape)));
                    vl.ShapeStyleAndIdStorage.Add(displayMassLoadStyleKey, new ConceptShapesStorageAndDisplayStyle(doMap.MassLoad.Color, doMap.MassLoad.Size, DisplayTypeConverterForGisMode(doMap.MassLoad.DisplayShape)));
                    vl.ShapeStyleAndIdStorage.Add(displayDefaultStyleKey, new ConceptShapesStorageAndDisplayStyle(System.Drawing.Color.Black, 8, DotSpatial.Symbology.PointShape.Ellipse));
                    vl.ShapeStyleAndIdStorage.Add(displayRiverStyleKey, new ConceptShapesStorageAndDisplayStyle(doMap.River.Color, doMap.River.Size, DisplayTypeConverterForGisMode(doMap.River.DisplayShape)));
                    vl.ShapeStyleAndIdStorage.Add(displaySeepageStyleKey, new ConceptShapesStorageAndDisplayStyle(doMap.Seepage.Color, doMap.Seepage.Size, DisplayTypeConverterForGisMode(doMap.Seepage.DisplayShape)));
                    vl.ShapeStyleAndIdStorage.Add(displaySpecifiedConcStyleKey, new ConceptShapesStorageAndDisplayStyle(doMap.SpecifiedConc.Color, doMap.SpecifiedConc.Size, DisplayTypeConverterForGisMode(doMap.SpecifiedConc.DisplayShape)));
                    vl.ShapeStyleAndIdStorage.Add(displaySpecifiedFlowStyleKey, new ConceptShapesStorageAndDisplayStyle(doMap.SpecifiedFlow.Color, doMap.SpecifiedFlow.Size, DisplayTypeConverterForGisMode(doMap.SpecifiedFlow.DisplayShape)));
                    vl.ShapeStyleAndIdStorage.Add(displaySpecifiedHeadStyleKey, new ConceptShapesStorageAndDisplayStyle(doMap.SpecifiedHead.Color, doMap.SpecifiedHead.Size, DisplayTypeConverterForGisMode(doMap.SpecifiedHead.DisplayShape)));
                    vl.ShapeStyleAndIdStorage.Add(displayWellStyleKey, new ConceptShapesStorageAndDisplayStyle(doMap.Well.Color, doMap.Well.Size, DisplayTypeConverterForGisMode(doMap.Well.DisplayShape)));


                    gl.AddChild(vl);
                    vl.ViewMode = _gisManager.VIEWMODE;
                    vl.PyLayer.IsVisible = false;

                    vl.Opacity = 0.3f;

                    List<VectorShape> vss = new List<VectorShape>();
                    foreach (FeatureObject fo in args.Coverage.Featureobjects)
                    {
                        if (fo is PointFO)
                        {
                            PointFO pt = (PointFO)fo;

                            PointShape ps = new PointShape(pt.Id, new Coordinate(pt.Coords.X, pt.Coords.Y));
                            ps.GroupName = ShapeGroupConversionTypeToStr(pt.SelectedSCType);

                            vss.Add(ps);
                        }
                        else if (fo is NodeFO)
                        {
                            NodeFO nf = (NodeFO)fo;

                            NodeShape ns = new NodeShape(nf.Id, new Coordinate(nf.Position.X, nf.Position.Y));

                            vss.Add(ns);
                        }
                        else if (fo is LineFO)
                        {
                            LineFO ln = (LineFO)fo;

                            List<Coordinate> coord = new List<Coordinate>();
                            foreach (HCoordinate item in ln.ToCoordinatesArray())
                            {
                                Coordinate c = new Coordinate(item.X, item.Y);
                                coord.Add(c);
                            }

                            LineShape ls = new LineShape(ln.Id, coord.ToArray(), ln.IsEnclosed);
                            ls.GroupName = ShapeGroupConversionTypeToStr(ln.SelectedSCType);

                            vss.Add(ls);
                        }
                        else if (fo is PolygonFO)
                        {
                            PolygonFO py = (PolygonFO)fo;

                            List<Coordinate> coord = new List<Coordinate>();
                            foreach (HCoordinate item in py.Coords)
                            {
                                Coordinate c = new Coordinate(item.X, item.Y);
                                coord.Add(c);
                            }

                            List<List<Coordinate>> holes = new List<List<Coordinate>>();
                            List<Coordinate> hole;

                            if (py.InnerHoles != null && py.InnerHoles.Count > 0)
                            {
                                foreach (List<HCoordinate> item in py.InnerHoles)
                                {
                                    hole = new List<Coordinate>();
                                    foreach (HCoordinate hCoordinate in item)
                                    {
                                        Coordinate c = new Coordinate(hCoordinate.X, hCoordinate.Y);
                                        hole.Add(c);
                                    }
                                    holes.Add(hole);
                                }
                            }

                            PolyShape ps = new PolyShape(py.Id, py.PolyKey, coord.ToArray(), holes);

                            ps.GroupName = ShapeGroupConversionTypeToStr(py.SelectedSCType);


                            vss.Add(ps);
                        }
                    }

                    vl.AddShape(vss);

                    break;
                case CollectionChangedType.REMOVE:

                    if (gl.Childs.Contains(this._gisManager.InteractiveSystem.CurrentLayer))
                        this._gisManager.InteractiveSystem.CurrentLayer = null;

                    gl.RemoveChild(args.Coverage.Key.ToString());

                    break;
                case CollectionChangedType.MOVE:
                    break;
                case CollectionChangedType.REPLACE:
                    break;
                case CollectionChangedType.RESET:
                    break;
                default:
                    break;
            }

        }

        /// <summary>
        /// 概念模型更改触发的操作
        /// </summary>
        /// <param name="args"></param>
        protected void OnModflowCollecionChanged(CollecionChangedEventArgs args)
        {
            Project project = ProjectService.DefaultService.Project;
            HA.Data.DisplayOptions2.DOMap doMap = project.DisplayOption2.DoMapData.Map;
            ConceptualModel item = (ConceptualModel)args.Child;
            if (item == null)
                return;
            GroupLayer gl = null;

            switch (args.Type)
            {
                case CollectionChangedType.ADD:

                    gl = new GroupLayer(item.Key.ToString());
                    gl.ViewMode = this._gisManager.VIEWMODE;
                    gl.Desc = item.Name;

                    this._gisManager.LayerSystem.LayerCollection.Add(gl);

                    break;
                case CollectionChangedType.REMOVE:

                    gl = (GroupLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(item.Key.ToString());

                    if (gl.Childs.Contains(this._gisManager.InteractiveSystem.CurrentLayer))
                        this._gisManager.InteractiveSystem.CurrentLayer = null;

                    this._gisManager.LayerSystem.LayerCollection.Remove(gl);

                    break;
                case CollectionChangedType.RESET:
                    break;
                default:
                    break;
            }

        }

        /// <summary>
        /// 源汇项更改触发的操作
        /// </summary>
        /// <param name="scArgs"></param>
        protected void OnSCCollectionChanged(SCColleconChangedEventArgs scArgs)
        {
            List<int[]> ijks = new List<int[]>();
            GridSourceSinksLayer gssLayer;

            switch (scArgs.ScType)
            {
                case SCType.RIVER:
                    foreach (River item in ProjectService.DefaultService.Project.MfData.SourceSinks.Rivers.InnerList)
                    {
                        ijks.Add(new int[] { item.I, item.J, item.K });
                    }
                    gssLayer = (GridSourceSinksLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(RiverLayerId);
                    if (gssLayer != null)
                    {
                        gssLayer.ClearPoint();
                        gssLayer.AddPoint(ijks);
                        gssLayer.Redraw();
                    }
                    break;
                case SCType.WELL:
                    foreach (Well item in ProjectService.DefaultService.Project.MfData.SourceSinks.Wells.InnerList)
                    {
                        ijks.Add(new int[] { item.I, item.J, item.K });
                    }
                    gssLayer = (GridSourceSinksLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(WellLayerId);
                    if (gssLayer != null)
                    {
                        gssLayer.ClearPoint();
                        gssLayer.AddPoint(ijks);
                        gssLayer.Redraw();
                    }
                    break;
                case SCType.EVT:
                    break;
                case SCType.RECHARGE:
                    break;
                case SCType.GHB:
                    foreach (GeneralHead item in ProjectService.DefaultService.Project.MfData.SourceSinks.GeneralHeads.InnerList)
                    {
                        ijks.Add(new int[] { item.I, item.J, item.K });
                    }
                    gssLayer = (GridSourceSinksLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(GHBLayerId);
                    if (gssLayer != null)
                    {
                        gssLayer.ClearPoint();
                        gssLayer.AddPoint(ijks);
                        gssLayer.Redraw();
                    }
                    break;
                case SCType.Drain:
                    foreach (Drain item in ProjectService.DefaultService.Project.MfData.SourceSinks.Drains.InnerList)
                    {
                        ijks.Add(new int[] { item.I, item.J, item.K });
                    }
                    gssLayer = (GridSourceSinksLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(DrainLayerId);
                    if (gssLayer != null)
                    {
                        gssLayer.ClearPoint();
                        gssLayer.AddPoint(ijks);
                        gssLayer.Redraw();
                    }
                    break;

                case SCType.SPECIFIEDHEAD:
                    foreach (SpecifiedHead item in ProjectService.DefaultService.Project.MfData.SourceSinks.SpecifiedHeads.InnerList)
                    {
                        ijks.Add(new int[] { item.I, item.J, item.K });
                    }
                    gssLayer = (GridSourceSinksLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(SpecifiedHeadLayerId);
                    if (gssLayer != null)
                    {
                        gssLayer.ClearPoint();
                        gssLayer.AddPoint(ijks);
                        gssLayer.Redraw();
                    }
                    break;

                case SCType.BARRIER:
                    BarrierLayer barrierLayer = (BarrierLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(BarrierLayerId);
                    if (barrierLayer != null)
                    {
                        barrierLayer.BarrierLocationIndexes = ProjectService.DefaultService.Project.MfData.HfbData.ToLocationList();
                        barrierLayer.Redraw();
                    }

                    break;

                default:
                    break;
            }
        }


        /// <summary>
        /// 刘加。向量图层改变事件
        /// </summary>
        protected void OnVectorLayerChanged()
        {
            if (ProjectService.DefaultService.Project.CurentFlowVectorData == null)
            {
                FlowVectorLayer vectorLayer1 = (FlowVectorLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(VectorLayerID);
                vectorLayer1.VectorValues = null;   //这一句内部已经封装了Update方法，下面这一句也留着吧，主要是有刷新，时间上没有浪费，刘查
                vectorLayer1.CurrentIBound = null;
                vectorLayer1.CurrentVectors = null;
                vectorLayer1.Update();
                return;
            }

            HAGISV2.FlowVectorValue[, ,] vectorValue = new FlowVectorValue[
                ProjectService.DefaultService.Project.CurentFlowVectorData.Vectors.GetLength(0),
                ProjectService.DefaultService.Project.CurentFlowVectorData.Vectors.GetLength(1),
                ProjectService.DefaultService.Project.CurentFlowVectorData.Vectors.GetLength(2)];

            for (int i = 0; i < ProjectService.DefaultService.Project.CurentFlowVectorData.Vectors.GetLength(0); i++)
            {
                for (int j = 0; j < ProjectService.DefaultService.Project.CurentFlowVectorData.Vectors.GetLength(1); j++)
                {
                    for (int k = 0; k < ProjectService.DefaultService.Project.CurentFlowVectorData.Vectors.GetLength(2); k++)
                    {
                        vectorValue[i, j, k] = new FlowVectorValue();
                        vectorValue[i, j, k].vx = ProjectService.DefaultService.Project.CurentFlowVectorData.Vectors[i, j, k].vx;
                        vectorValue[i, j, k].vy = ProjectService.DefaultService.Project.CurentFlowVectorData.Vectors[i, j, k].vy;
                        vectorValue[i, j, k].vz = ProjectService.DefaultService.Project.CurentFlowVectorData.Vectors[i, j, k].vz;

                    }
                }
            }

            //HeadGrid headGrid = ProjectSerivce.DefaultService.Project.Grid3dData.MainGrid.ModFlowGrid.GetHeadGrid();

            Domain.DomainLayer.GridData gd = ProjectService.DefaultService.Project.Grid3dData.MainGrid.ModFlowGrid;
            Coordinate[, ,] coord3D = AlgorithmHelper.ConvertCoordinatesFor2D(ProjectService.DefaultService.Project.Grid3dData.MainGrid.ModFlowGrid.GetHeadGrid().GridHeads,
                ProjectService.DefaultService.Project.DisplayOption2.ZMagnification);

            HyGrid hg = new HyGrid(gd.RowsCount, gd.ColsCount, gd.LayersCount, gd.RowCoords, gd.ColCoords, gd.LayerCoords, gd.OrgX, gd.OrgY, gd.OrgZ, gd.RotationZ, coord3D);

            FlowVectorLayer vectorLayer = (FlowVectorLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(VectorLayerID);

            //if (vectorLayer == null)
            //{
            //    vectorLayer = new FlowVectorLayer(VectorLayerID, hg, vectorValue);
            //    this._gisManager.LayerSystem.LayerCollection.Add(vectorLayer);
            //}
            //else
            //{
            vectorLayer.SetGrid(hg);            
                       
            vectorLayer.SetVectorValues(vectorValue);

            vectorLayer.SetIBount(ProjectService.DefaultService.Project.CurentFlowVectorData.EffIBound);

            //ProjectSerivce.DefaultService.Project.DisplayOption .Grid3d.Vector.IsVaryLength //是否使用定长、不定长（true）
            //ProjectSerivce .DefaultService .Project .DisplayOption .Grid3d .Vector .Length  //定长长度
            //ProjectSerivce.DefaultService .Project .DisplayOption .Grid3d .Vector .Scaling //缩放比例

            //}

            //vectorLayer.Boundary = GetNeededGridInfo.TranslateList2DTo3D(vectorLayer.Grid, ProjectSerivce.DefaultService.Project.CurrentDSData.EffIBound); 
            vectorLayer.Visible = ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.IsShowVector;
            vectorLayer.SetPara(ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Vector.IsVaryLength,
                   ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Vector.Length,
                   ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Vector.Scaling,
                   ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Vector.VectorColor);

            vectorLayer.Update();

        }
        
        /// <summary>
        /// 向量图层参数发生改变时
        /// </summary>
        protected void OnVectorParaChanged()
        {
            FlowVectorLayer vectorLayer = (FlowVectorLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(VectorLayerID);

            if (vectorLayer != null)
            {
                vectorLayer.SetPara(ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Vector.IsVaryLength,
                    ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Vector.Length,
                    ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Vector.Scaling,
                    ProjectService .DefaultService.Project.DisplayOption2.DoGrid3dData .Grid3d.Vector .VectorColor);
            }



        }

        /// <summary>
        /// 等值线更改触发的操作
        /// </summary>
        /// <param name="dsArgs"></param>
        protected void OnCurrentDataSetChanged()
        {
            IsolineLayer isolineLayer = (IsolineLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(IsolineLayerId);
            
            if (isolineLayer == null)
                throw new NullReferenceException("等值线图层实例为空！运行GisMoudle.OnCurrentDataSetChanged方法时发现！");

            isolineLayer.IsLegendTextFormat = ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Contour.IsUseScientificNotation;
            isolineLayer.LegendFormatNum = ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Contour.DecimalDigitNum;
            isolineLayer.LableFormatNum = ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Contour.DecimalDigitNum;
            isolineLayer.IsLabelTextFormat = ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Contour.IsUseScientificNotation; 


            //读取对应的结果水头数据
            CellCenterDataSet3d ccds3D = ProjectService.DefaultService.Project.CurrentDSData;
            if (isolineLayer.HyGrid == null || ccds3D == null)
            {
                isolineLayer.IsoLineValues.Clear();
                isolineLayer.LineColorList.Clear();
                isolineLayer.LineFillColorList.Clear();

                isolineLayer.SetContourLineList();

                isolineLayer.Redraw();

                return;
            }

            isolineLayer.Boundary = GetNeededGridInfo.TranslateList2DTo3D(isolineLayer.HyGrid, ccds3D.EffIBound);
            isolineLayer.InvalidValue = ccds3D.InvalidValue;
            isolineLayer.IsolineSourceDatas = ccds3D.Datas;

            

            List<LinearContourColorValue> lineValueColor = ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Contour.ContourLines;

            isolineLayer.IsoLineValues.Clear();
            isolineLayer.LineColorList.Clear();
            isolineLayer.LineFillColorList.Clear();

            for (int i = 0; i < lineValueColor.Count; i++)
            {
                isolineLayer.IsoLineValues.Add(lineValueColor[i].Value);
                isolineLayer.LineColorList.Add(lineValueColor[i].Color);
                isolineLayer.LineFillColorList.Add(lineValueColor[i].Color);
            }

            isolineLayer.SetContourLineList();

            isolineLayer.Redraw();

        }

        /// <summary>
        /// 刘加，新的 等值线更改触发的操作
        /// </summary>
        protected void OnContourLineChanged(ProjectUIEventArgs e)
        {
            IsolineLayer isolineLayer = (IsolineLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(IsolineLayerId);

            if (isolineLayer == null)
                return;

            if (isolineLayer.HyGrid == null)
            {
                return;
            }
            
            //以上是以前的代码，下面是新加代码  ，刘

             ContourSetupChangedEventArgs ContourChangeArgs = (ContourSetupChangedEventArgs)e.Param;

            switch (ContourChangeArgs.Type )  //分情况，是哪些属性发生了变化
            {
                case  ContourSetupChangedType.ContourLineValueList:

                    isolineLayer.IsLegendTextFormat = ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Contour.IsUseScientificNotation;
                    isolineLayer.LegendFormatNum = ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Contour.DecimalDigitNum;
                    isolineLayer.LableFormatNum = ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Contour.DecimalDigitNum;
                    isolineLayer.IsLabelTextFormat = ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Contour.IsUseScientificNotation; 


                    List <double > values=new List<double> ();
                     isolineLayer.LineColorList.Clear();
                            isolineLayer.LineFillColorList.Clear();
                    foreach (LinearContourColorValue value in  ProjectService .DefaultService .Project .DisplayOption2 .DoGrid3dData .Grid3d .Contour.ContourLines )
                    {
                        values.Add (value .Value );
                        isolineLayer.LineColorList.Add(value.Color);
                        isolineLayer.LineFillColorList.Add(value.Color);
                    }
                    if (values .Count <=0) return ;
                    
                    isolineLayer.IsoLineValues = values;
                    isolineLayer.SetContourLineList();
                    isolineLayer.Redraw();

                    break;
                case ContourSetupChangedType.ContourLine: //等值线本身发生了变化

                    isolineLayer.IsLegendTextFormat = ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Contour.IsUseScientificNotation;
                    isolineLayer.LegendFormatNum = ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Contour.DecimalDigitNum;
                    isolineLayer.LableFormatNum = ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Contour.DecimalDigitNum;
                    isolineLayer.IsLabelTextFormat = ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Contour.IsUseScientificNotation;
                    isolineLayer.IsGenerateIsolineByCenter = ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Contour.IsUseCellRealData;

                    switch (ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Contour.ContourType)
                    {
                        //判断等值线的绘制是哪种模式
                        case ContourDisplayType.Linear : //只绘制线

                            //ProjectSerivce.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Contour .

                            //isolineLayer.StartEdit(); //开始编辑属性，编辑时不进行重绘操做

                            isolineLayer.IsShowContourFill = false; //线模式下不显示面
                            isolineLayer.IsLineVisble = true;
                                                       
                            isolineLayer.LineColorList.Clear();
                            isolineLayer.LineFillColorList.Clear();                           
                            foreach (LinearContourColorValue value in ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Contour.ContourLines)
                            {                              
                                isolineLayer.LineColorList.Add(value.Color);
                                isolineLayer.LineFillColorList.Add(value.Color);
                            }

                            isolineLayer.SetContourLineList();

                            isolineLayer.LineWidth = ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Contour.LineWidth;
                            isolineLayer.IsShowLabel = ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Contour.ContourLineProperty.LineTagging.IsShowTagging;
                            isolineLayer.LineColor = ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Contour.LineColor;
                            //isolineLayer.EndEdit(); //结束属性编辑 ，方法内部调用重绘操做

                            break;
                        case ContourDisplayType.ColorFill: //只绘制面

                            //isolineLayer.StartEdit();

                            isolineLayer.LineColorList.Clear();
                            isolineLayer.LineFillColorList.Clear();
                            foreach (LinearContourColorValue value in ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Contour.ContourLines)
                            {
                                isolineLayer.LineColorList.Add(value.Color);
                                isolineLayer.LineFillColorList.Add(value.Color);
                            }

                            isolineLayer.SetContourLineList();

                            isolineLayer.IsShowContourFill = true;
                            isolineLayer.IsLineVisble = false;
                            isolineLayer.IsShowLabel = false;

                            //isolineLayer.EndEdit();

                            break;
                        case ContourDisplayType.LinearAndColorFill : //同时绘制线和面

                            //isolineLayer.StartEdit();

                            isolineLayer.IsShowContourFill = true;
                            isolineLayer.IsLineVisble = true;

                            isolineLayer.LineColorList.Clear();
                            isolineLayer.LineFillColorList.Clear();
                            foreach (LinearContourColorValue value in ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Contour.ContourLines)
                            {
                                isolineLayer.LineColorList.Add(value.Color);
                                isolineLayer.LineFillColorList.Add(value.Color);
                            }

                            isolineLayer.SetContourLineList();

                            isolineLayer.LineColor = ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Contour.LineColor;
                            isolineLayer.LineWidth = ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Contour.LineWidth;

                            isolineLayer.IsShowLabel = ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Contour.ContourLineProperty.LineTagging.IsShowTagging;


                            //isolineLayer.EndEdit();

                            break;
                    }

                    break ;
                case  ContourSetupChangedType.ScalarBar :  //图例发生变化

                    //ProjectSerivce .DefaultService .Project .DisplayOption2 .DoGrid3dData .Grid3d .Contour.ContourLineProperty.LineScalarBar.

                    foreach (string str in ContourChangeArgs.PropNames)
                    {
                        ScalarBarChangedType typeSalarBar = (ScalarBarChangedType)Enum.Parse(typeof(ScalarBarChangedType), str);

                        switch (typeSalarBar)
                        {
                            case ScalarBarChangedType.ScalarBarSetup:

                                //主程 那边的命名好像有错误

                                //图例是一个特殊的存在，是直接绘制在控件上
                                //只有出图的时候才绘到图层上
                                //isolineLayer.StartEdit(); 

                                isolineLayer.IsShowLegend = ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Contour.ContourLineProperty.LineScalarBar.IsShowScalarBar;
                                isolineLayer.LegendColor = ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Contour.ContourLineProperty.LineScalarBar.LabelColor;
                                //isolineLayer.IsLegendTextFormat = ProjectSerivce.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Contour.IsSpecifyPrecision;
                                //isolineLayer.LegendFormatNum = ProjectSerivce.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Contour.DecimalDigitNum;
                                isolineLayer.LegendFont = new System.Drawing.Font(isolineLayer.LegendFont.FontFamily, (float)ProjectService.DefaultService.Project.DisplayOption2.
                                    DoGrid3dData.Grid3d.Contour.ContourLineProperty.LineScalarBar.LabelFontSize);

                                //isolineLayer.LegendWidth = (float)ProjectSerivce.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Contour.ContourLineProperty.LineScalarBar.Width / 100*this.GisManager .CurrentMap.Width;
                                //isolineLayer.LegendHeight = (float)ProjectSerivce.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Contour.ContourLineProperty.LineScalarBar.Height / 100;

                                //isolineLayer.LegendOffsetX =(double)ProjectSerivce.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Contour.ContourLineProperty.LineScalarBar.XToViewPortLeftUper/100* this.GisManager.CurrentMap.Width; //  / 100 * this.GisManager.CurrentMap.Width - this.GisManager.CurrentMap.Width;
                                //isolineLayer.LegendOffsetY = (double)ProjectSerivce.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Contour.ContourLineProperty.LineScalarBar.YToViewPortLeftUper/100 * this.GisManager.CurrentMap.Height; // / 100 * this.GisManager.CurrentMap.Height;

                            //isolineLayer.EndEdit();

                                break;
                            default:
                                break;
                        }
                    }

                    break ;
                case ContourSetupChangedType.Tagging :  //标注发生变化

                    for (int i = 0; i < ContourChangeArgs.PropNames.Count; i++)
                    {
                        //字符串转换成枚举值
                        TaggingChangedType typeSalarBar = (TaggingChangedType)Enum.Parse(typeof(TaggingChangedType), ContourChangeArgs.PropNames[i]);                        

                        switch (typeSalarBar)
                        {
                            case TaggingChangedType.TaggingSetup:

                                //isolineLayer.StartEdit();
                                if (ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Contour.ContourType == ContourDisplayType.ColorFill)
                                {
                                    isolineLayer.IsShowLabel = false;
                                }
                                else
                                {
                                    isolineLayer.IsShowLabel = ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Contour.ContourLineProperty.LineTagging.IsShowTagging;
                                }
                                isolineLayer.LabelColor = ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Contour.ContourLineProperty.LineTagging.TagColor;
                                
                                //图例的字体样式主程也没有对应的字段
                            //isolineLayer .LabelFont =ProjectSerivce .DefaultService .Project .DisplayOption2 .DoGrid3dData .Grid3d .Contour .ContourLineProperty .LineTagging .FontSize 

                                isolineLayer.LabelNum = ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Contour.ContourLineProperty.LineTagging.MaskPointNum;
                                //isolineLayer.StepNum = ProjectSerivce.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Contour.IsSpecifyPrecision 

                                //小数点位数没用了
                                //isolineLayer.LableFormatNum = ProjectSerivce.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Contour.DecimalDigitNum;                               
                                //isolineLayer.IsLabelTextFormat = ProjectSerivce.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Contour.IsSpecifyPrecision; 
                                isolineLayer.LabelColor = ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Contour.ContourLineProperty.LineTagging.TagColor;

                                isolineLayer.LabelFont = new System.Drawing.Font("Times New Roman", (float)ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Contour.ContourLineProperty.LineTagging.FontSize);

                                //isolineLayer.EndEdit();

                                break;
                            default:
                                break;
                        }
                    }

                    break ;
            }

            this._gisManager.CurrentMap.Refresh();

        }

        /// <summary>
        /// 图形的MapSCType与groupName转换以便对应
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        string ShapeGroupConversionTypeToStr(MAPSCType type)
        {
            switch (type)
            {
                //case MAPSCType.LAYERRANGE:
                //    break;
                case MAPSCType.WELL:
                    return displayWellStyleKey;
                //case MAPSCType.REFINEPOINTS:
                //    break;
                case MAPSCType.SPECIFIEDHEAD:
                    return displaySpecifiedHeadStyleKey;
                case MAPSCType.SPECIFIEDFLOW:
                    return displaySpecifiedFlowStyleKey;
                case MAPSCType.GENERALHEAD:
                    return displayGeneralHeadStyleKey;
                case MAPSCType.DRAIN:
                    return displayDrainStyleKey;
                case MAPSCType.RIVER:
                    return displayRiverStyleKey;
                //case MAPSCType.LAKE:
                //    break;
                case MAPSCType.BARRIER:
                    return displayBarrierStyleKey;
                //case MAPSCType.OBSERVEDFLOW:
                //    break;
                //case MAPSCType.TANSOBSERVEDFLOW:
                //    break;
                case MAPSCType.SEEPAGEFACE:
                    return displaySeepageStyleKey;
                case MAPSCType.NONE:
                    return displayDefaultStyleKey;
                case MAPSCType.MASSLOADING:
                    return displayMassLoadStyleKey;
                case MAPSCType.SPECIFIEDCONC:
                    return displaySpecifiedConcStyleKey;
                default:
                    break;
            }
            return "Default";
        }
        protected void OnFOChanged(FOCollecionChangedEventArgs args)
        {
            VectorLayer vl = (VectorLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(args.Coverage.Key.ToString());

            List<VectorShape> vss = new List<VectorShape>();

            Dictionary<string, string> idAndGroupNames;

            switch (args.Type)
            {
                case CollectionChangedType.ADD:

                    foreach (FeatureObject fo in args.FoesModified)
                    {
                        if (fo is PointFO)
                        {
                            PointFO pt = (PointFO)fo;

                            PointShape ps = new PointShape(pt.Id, new Coordinate(pt.Coords.X, pt.Coords.Y));
                            ps.GroupName = ShapeGroupConversionTypeToStr(pt.SelectedSCType);

                            vss.Add(ps);
                        }
                        else if (fo is NodeFO)
                        {
                            NodeFO nf = (NodeFO)fo;

                            NodeShape ns = new NodeShape(nf.Id, new Coordinate(nf.Position.X, nf.Position.Y));

                            vss.Add(ns);
                        }
                        else if (fo is LineFO)
                        {
                            LineFO ln = (LineFO)fo;

                            List<Coordinate> coord = new List<Coordinate>();

                            foreach (HCoordinate item in ln.ToCoordinatesArray(1))
                            {
                                Coordinate c = new Coordinate(item.X, item.Y);
                                coord.Add(c);
                            }

                            LineShape ls = new LineShape(ln.Id, coord.ToArray(), ln.IsEnclosed);
                            ls.GroupName = ShapeGroupConversionTypeToStr(ln.SelectedSCType);

                            vss.Add(ls);
                        }
                        else if (fo is PolygonFO)
                        {
                            PolygonFO py = (PolygonFO)fo;

                            List<Coordinate> coord = new List<Coordinate>();
                            foreach (HCoordinate item in py.Coords)
                            {
                                Coordinate c = new Coordinate(item.X, item.Y);
                                coord.Add(c);
                            }

                            List<List<Coordinate>> holes = new List<List<Coordinate>>();
                            List<Coordinate> hole;

                            if (py.InnerHoles != null && py.InnerHoles.Count > 0)
                            {
                                foreach (List<HCoordinate> item in py.InnerHoles)
                                {
                                    hole = new List<Coordinate>();
                                    foreach (HCoordinate hCoordinate in item)
                                    {
                                        Coordinate c = new Coordinate(hCoordinate.X, hCoordinate.Y);
                                        hole.Add(c);
                                    }
                                    holes.Add(hole);
                                }
                            }

                            PolyShape ps = new PolyShape(py.Id, py.PolyKey, coord.ToArray(), holes);
                            ps.GroupName = ShapeGroupConversionTypeToStr(py.SelectedSCType);

                            vss.Add(ps);
                        }
                    }

                    vl.AddShape(vss);


                    break;
                case CollectionChangedType.REMOVE:

                    foreach (FeatureObject item in args.FoesModified)
                    {
                        if (item != null)
                            vss.Add(vl.GetShape(item.Id));
                    }

                    vl.RemoveShape(vss);

                    break;
                case CollectionChangedType.MOVE:
                    break;
                case CollectionChangedType.REPLACE:

                    //foreach (FeatureObject fo in args.Coverage.Featureobjects)
                    //{
                    //    if (fo is PointFO)
                    //    {
                    //        PointFO pt = (PointFO)fo;

                    //        PointShape ps = new PointShape(pt.Id, new Coordinate(pt.Coords.X, pt.Coords.Y));
                    //        ps.GroupName = ShapeGroupConversionTypeToStr(pt.SelectedSCType);

                    //        vss.Add(ps);
                    //    }
                    //    else if (fo is NodeFO)
                    //    {
                    //        NodeFO nf = (NodeFO)fo;

                    //        NodeShape ns = new NodeShape(nf.Id, new Coordinate(nf.Position.X, nf.Position.Y));

                    //        vss.Add(ns);
                    //    }
                    //    else if (fo is LineFO)
                    //    {
                    //        LineFO ln = (LineFO)fo;

                    //        List<Coordinate> coord = new List<Coordinate>();
                    //        foreach (HCoordinate item in ln.ToCoordinatesArray())
                    //        {
                    //            Coordinate c = new Coordinate(item.X, item.Y);
                    //            coord.Add(c);
                    //        }

                    //        LineShape ls = new LineShape(ln.Id, coord.ToArray(), ln.IsEnclosed);
                    //        ls.GroupName = ShapeGroupConversionTypeToStr(ln.SelectedSCType);

                    //        vss.Add(ls);
                    //    }
                    //    else if (fo is PolygonFO)
                    //    {
                    //        PolygonFO py = (PolygonFO)fo;

                    //        List<Coordinate> coord = new List<Coordinate>();
                    //        foreach (HCoordinate item in py.Coords)
                    //        {
                    //            Coordinate c = new Coordinate(item.X, item.Y);
                    //            coord.Add(c);
                    //        }

                    //        List<List<Coordinate>> holes = new List<List<Coordinate>>();
                    //        List<Coordinate> hole;

                    //        if (py.InnerHoles != null && py.InnerHoles.Count > 0)
                    //        {
                    //            foreach (List<HCoordinate> item in py.InnerHoles)
                    //            {
                    //                hole = new List<Coordinate>();
                    //                foreach (HCoordinate hCoordinate in item)
                    //                {
                    //                    Coordinate c = new Coordinate(hCoordinate.X, hCoordinate.Y);
                    //                    hole.Add(c);
                    //                }
                    //                holes.Add(hole);
                    //            }
                    //        }

                    //        PolyShape ps = new PolyShape(py.Id, py.PolyKey, coord.ToArray(), holes);

                    //        ps.GroupName = ShapeGroupConversionTypeToStr(py.SelectedSCType);

                    //        vss.Add(ps);
                    //    }
                    //}

                    //vl.EditShape(vss);



                    break;
                case CollectionChangedType.RESET:
                    vl.ClearSelection();
                    vl.ClearShape();

                    List<VectorShape> vshps = new List<VectorShape>();
                    foreach (FeatureObject fo in args.Coverage.Featureobjects)
                    {
                        if (fo is PointFO)
                        {
                            PointFO pt = (PointFO)fo;

                            PointShape ps = new PointShape(pt.Id, new Coordinate(pt.Coords.X, pt.Coords.Y));
                            ps.GroupName = ShapeGroupConversionTypeToStr(pt.SelectedSCType);

                            vshps.Add(ps);
                        }
                        else if (fo is NodeFO)
                        {
                            NodeFO node = (NodeFO)fo;

                            NodeShape ns = new NodeShape(node.Id, new Coordinate(node.Position.X, node.Position.Y));

                            vshps.Add(ns);
                        }
                        else if (fo is LineFO)
                        {
                            LineFO ln = (LineFO)fo;

                            List<Coordinate> coord = new List<Coordinate>();
                            foreach (HCoordinate item in ln.ToCoordinatesArray())
                            {
                                Coordinate c = new Coordinate(item.X, item.Y);
                                coord.Add(c);
                            }

                            LineShape ls = new LineShape(ln.Id, coord.ToArray(), ln.IsEnclosed);
                            ls.GroupName = ShapeGroupConversionTypeToStr(ln.SelectedSCType);

                            vshps.Add(ls);
                        }
                        else if (fo is PolygonFO)
                        {
                            PolygonFO py = (PolygonFO)fo;

                            List<Coordinate> coord = new List<Coordinate>();
                            foreach (HCoordinate item in py.Coords)
                            {
                                Coordinate c = new Coordinate(item.X, item.Y);
                                coord.Add(c);
                            }

                            List<List<Coordinate>> holes = new List<List<Coordinate>>();
                            List<Coordinate> hole;

                            if (py.InnerHoles != null && py.InnerHoles.Count > 0)
                            {
                                foreach (List<HCoordinate> item in py.InnerHoles)
                                {
                                    hole = new List<Coordinate>();
                                    foreach (HCoordinate hCoordinate in item)
                                    {
                                        Coordinate c = new Coordinate(hCoordinate.X, hCoordinate.Y);
                                        hole.Add(c);
                                    }
                                    holes.Add(hole);
                                }
                            }

                            PolyShape ps = new PolyShape(py.Id, py.PolyKey, coord.ToArray(), holes);

                            ps.GroupName = ShapeGroupConversionTypeToStr(py.SelectedSCType);

                            vshps.Add(ps);
                        }
                    }

                    vl.AddShape(vshps);

                    break;
                case CollectionChangedType.ITEMEDIT:
                    
                    foreach (FeatureObject fo in args.FoesModified)
                    {
                        if (fo is PointFO)
                        {
                            PointFO pt = (PointFO)fo;

                            PointShape ps = new PointShape(pt.Id, new Coordinate(pt.Coords.X, pt.Coords.Y));
                            ps.GroupName = ShapeGroupConversionTypeToStr(pt.SelectedSCType);

                            vss.Add(ps);
                        }
                        else if (fo is NodeFO)
                        {
                            NodeFO nf = (NodeFO)fo;

                            NodeShape ns = new NodeShape(nf.Id, new Coordinate(nf.Position.X, nf.Position.Y));

                            vss.Add(ns);
                        }
                        else if (fo is LineFO)
                        {
                            LineFO ln = (LineFO)fo;

                            List<Coordinate> coord = new List<Coordinate>();
                            foreach (HCoordinate item in ln.ToCoordinatesArray())
                            {
                                Coordinate c = new Coordinate(item.X, item.Y);
                                coord.Add(c);
                            }

                            LineShape ls = new LineShape(ln.Id, coord.ToArray(), ln.IsEnclosed);
                            ls.GroupName = ShapeGroupConversionTypeToStr(ln.SelectedSCType);

                            vss.Add(ls);
                        }
                        else if (fo is PolygonFO)
                        {
                            PolygonFO py = (PolygonFO)fo;

                            List<Coordinate> coord = new List<Coordinate>();
                            foreach (HCoordinate item in py.Coords)
                            {
                                Coordinate c = new Coordinate(item.X, item.Y);
                                coord.Add(c);
                            }

                            List<List<Coordinate>> holes = new List<List<Coordinate>>();
                            List<Coordinate> hole;

                            if (py.InnerHoles != null && py.InnerHoles.Count > 0)
                            {
                                foreach (List<HCoordinate> item in py.InnerHoles)
                                {
                                    hole = new List<Coordinate>();
                                    foreach (HCoordinate hCoordinate in item)
                                    {
                                        Coordinate c = new Coordinate(hCoordinate.X, hCoordinate.Y);
                                        hole.Add(c);
                                    }
                                    holes.Add(hole);
                                }
                            }

                            PolyShape ps = new PolyShape(py.Id, py.PolyKey, coord.ToArray(), holes);

                            ps.GroupName = ShapeGroupConversionTypeToStr(py.SelectedSCType);

                            vss.Add(ps);
                        }
                    }

                    vl.EditShape(vss);

                    break;

                case CollectionChangedType.MODIFYDATATYPES:
                    //key为Id，Value为groupName
                    idAndGroupNames = new Dictionary<string, string>();
                    foreach (FeatureObject fo in args.Coverage.Featureobjects)
                    {
                        idAndGroupNames.Add(fo.Id, ShapeGroupConversionTypeToStr(fo.SelectedSCType));
                    }

                    vl.EditShapeObjectType(idAndGroupNames);

                    break;

                default:
                    break;
            }

        }

        /// <summary>
        /// 概念模型网格框更改触发的操作
        /// </summary>
        /// <param name="args"></param>
        protected void OnModifiedGridFrame(ObjectOperationEventArgs args)
        {
            GridFrame gf;
            ConceptFrameLayer cl;
            RectangleFrame rf;
            Layer layer;

            switch (args.OperationType)
            {
                case ObjectOperationType.ADD:

                    gf = ProjectService.DefaultService.Project.MapData.GridFrame;
                    cl = new ConceptFrameLayer(GridFrameLayerId, new RectangleFrame(new Coordinate(gf.XOrg, gf.YOrg, 0), gf.XLength, gf.YLength, gf.RotateAngle));

                    this._gisManager.LayerSystem.LayerCollection.Add(cl);
                    cl.ViewMode = _gisManager.VIEWMODE;

                    break;
                case ObjectOperationType.REMOVE:

                    layer = _gisManager.LayerSystem.LayerCollection.GetLayer(GridFrameLayerId);
                    if (layer != null)
                    {
                        if (layer == this._gisManager.InteractiveSystem.CurrentLayer)
                            this._gisManager.InteractiveSystem.CurrentLayer = null;
                        this._gisManager.LayerSystem.LayerCollection.Remove(layer);
                    }
                    break;
                case ObjectOperationType.MODIFY:

                    gf = ProjectService.DefaultService.Project.MapData.GridFrame;
                    cl = (ConceptFrameLayer)_gisManager.LayerSystem.LayerCollection.GetLayer(GridFrameLayerId);

                    if (cl != null)
                    {
                        rf = cl.RectFrame;
                        rf.LeftBottomCoordinate.X = gf.XOrg;
                        rf.LeftBottomCoordinate.Y = gf.YOrg;
                        rf.Width = gf.XLength;
                        rf.Height = gf.YLength;

                        rf.Rotation = gf.RotateAngle;

                        cl.RectFrame = rf;
                    }

                    break;
                default:
                    break;
            }

        }

        /// <summary>
        /// 重置网格触发的操作
        /// </summary>
        /// <param name="args"></param>
        protected void OnResetGrid(CollecionChangedEventArgs args)
        {
            //id在gis中为固定Id
            GroupLayer gl = (GroupLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(GridGroupLayerId);

            HydrolicGridLayer hgLayer;
            Project project = ProjectService.DefaultService.Project;
            DotSpatial.Topology.Coordinate[, ,] coord3D;
            HyGrid hg;
            IsolineLayer isolineLayer;
            FlowVectorLayer vectorLayer;
            List<int[,]> iBounds;

            HA.ModFlow.Domain.DomainLayer.GridData gd;

            switch (args.Type)
            {
                case CollectionChangedType.ADD:

                    if (project.Grid3dData.Grids.Count > 0)
                    {
                        Grid3d grid3d = project.Grid3dData.MainGrid;
                        iBounds = grid3d.ModFlowGrid.WaterGrid.GetIBounds();

                        coord3D = AlgorithmHelper.ConvertCoordinatesFor2D(project.Grid3dData.MainGrid.ModFlowGrid.GetBoundGrid().GridPoints, project.DisplayOption2.ZMagnification);
                        hg = new HyGrid
                            (
                            grid3d.ModFlowGrid.RowsCount, grid3d.ModFlowGrid.ColsCount, grid3d.ModFlowGrid.LayersCount,
                            grid3d.ModFlowGrid.RowCoords, grid3d.ModFlowGrid.ColCoords, grid3d.ModFlowGrid.LayerCoords, grid3d.ModFlowGrid.OrgX,
                            grid3d.ModFlowGrid.OrgY, grid3d.ModFlowGrid.OrgZ, grid3d.ModFlowGrid.RotationZ, coord3D
                            );

                        hgLayer = new HydrolicGridLayer(GridLayerId, hg, iBounds);

                        hgLayer.Desc = grid3d.Name;

                        gl.AddChild(hgLayer);

                        isolineLayer = (IsolineLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(this.IsolineLayerId);
                        if (isolineLayer != null)
                        {
                            isolineLayer.ResetGridData(hg, iBounds);
                            isolineLayer.ContourLineList = new List<ContourLine>();
                            isolineLayer.Redraw();
                        }

                        //流量线图层重置网格数据
                        coord3D = AlgorithmHelper.ConvertCoordinatesFor2D(ProjectService.DefaultService.Project.Grid3dData.MainGrid.ModFlowGrid.GetHeadGrid().GridHeads,
                           ProjectService.DefaultService.Project.DisplayOption2.ZMagnification);

                        hg = new HyGrid(grid3d.ModFlowGrid.RowsCount, grid3d.ModFlowGrid.ColsCount, grid3d.ModFlowGrid.LayersCount, grid3d.ModFlowGrid.RowCoords,
                            grid3d.ModFlowGrid.ColCoords, grid3d.ModFlowGrid.LayerCoords, grid3d.ModFlowGrid.OrgX, grid3d.ModFlowGrid.OrgY, grid3d.ModFlowGrid.OrgZ, grid3d.ModFlowGrid.RotationZ, coord3D);

                        vectorLayer = (FlowVectorLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(VectorLayerID);
                        vectorLayer.SetGrid(hg);
                        vectorLayer.SetVectorValues(null);
                        vectorLayer.Update();

                        this._gisManager.ZoomToCurrentLayer(hgLayer.Id);
                    }

                    break;
                case CollectionChangedType.REMOVE:

                    if (gl.Childs.Contains(this._gisManager.InteractiveSystem.CurrentLayer))
                        this._gisManager.InteractiveSystem.CurrentLayer = null;
                    gl.RemoveAllChild();

                    isolineLayer = (IsolineLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(this.IsolineLayerId);
                    if (isolineLayer != null)
                    {
                        isolineLayer.ResetGridData(null, null);
                        isolineLayer.ContourLineList = new List<ContourLine>();
                        isolineLayer.Redraw();
                    }

                    vectorLayer = (FlowVectorLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(this.VectorLayerID);
                    if (vectorLayer != null)
                    {
                        vectorLayer.SetGrid(null);
                        vectorLayer.SetVectorValues(null);
                        vectorLayer.Update();
                    }

                    this._gisManager.VIEWMODE = FMAPVIEW.NORMAL;

                    this.SetGridLayerNum(1);


                    break;
                case CollectionChangedType.MOVE:

                    //GridSourceSinksLayer gssLayer;
                    //gd = ProjectSerivce.DefaultService.Project.Grid3dData.MainGrid.ModFlowGrid;
                    //coord3D = AlgorithmHelper.ConvertCoordinatesFor2D(ProjectSerivce.DefaultService.Project.Grid3dData.MainGrid.ModFlowGrid.GetBoundGrid().GridPoints);
                    //hg = new HyGrid(gd.RowsCount, gd.ColsCount, gd.LayersCount, gd.RowCoords, gd.ColCoords, gd.LayerCoords, gd.OrgX, gd.OrgY, gd.OrgZ, gd.RotationZ, coord3D);



                    /////测试网格
                    /////
                    //List<int[,]> iBounds = gd.WaterGrid.GetIBounds();
                    //hgLayer = (HydrolicGridLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(gridId);
                    //if (hgLayer != null) hgLayer.ResetGridData(hg, iBounds);

                    //gssLayer = (GridSourceSinksLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(riverId);
                    //if (gssLayer != null) gssLayer.ResetGridData(hg, iBounds);

                    //gssLayer = (GridSourceSinksLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(wellId);
                    //if (gssLayer != null) gssLayer.ResetGridData(hg, iBounds);

                    //gssLayer = (GridSourceSinksLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(ghbId);
                    //if (gssLayer != null) gssLayer.ResetGridData(hg, iBounds);

                    //gssLayer = (GridSourceSinksLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(drainId);
                    //if (gssLayer != null) gssLayer.ResetGridData(hg, iBounds);

                    //gssLayer = (GridSourceSinksLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(specifiedHeadId);
                    //if (gssLayer != null) gssLayer.ResetGridData(hg, iBounds);

                    //gssLayer = (GridSourceSinksLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(iBoundId);
                    //if (gssLayer != null)
                    //{
                    //    gssLayer.ResetGridData(hg, iBounds);

                    //    List<int[]> ijks = new List<int[]>();
                    //    for (int k = 0; k < gssLayer.Boundary.GetLength(0); k++)
                    //    {
                    //        for (int j = 0; j < gssLayer.Boundary.GetLength(1); j++)
                    //        {
                    //            for (int i = 0; i < gssLayer.Boundary.GetLength(2); i++)
                    //            {
                    //                if (gssLayer.Boundary[k, j, i] < 0)
                    //                    ijks.Add(new int[] { j + 1, i + 1, k + 1 });
                    //            }
                    //        }


                    //    }
                    //    gssLayer.ClearPoint();
                    //    gssLayer.AddPoint(ijks);
                    //    gssLayer.Redraw();
                    //}

                    break;
                case CollectionChangedType.REPLACE:

                    gd = ProjectService.DefaultService.Project.Grid3dData.MainGrid.ModFlowGrid;
                    iBounds = gd.WaterGrid.GetIBounds();
                    coord3D = AlgorithmHelper.ConvertCoordinatesFor2D(project.Grid3dData.MainGrid.ModFlowGrid.GetBoundGrid().GridPoints, project.DisplayOption2.ZMagnification);
                    hg = new HyGrid(gd.RowsCount, gd.ColsCount, gd.LayersCount, gd.RowCoords, gd.ColCoords, gd.LayerCoords, gd.OrgX, gd.OrgY, gd.OrgZ, gd.RotationZ, coord3D);

                    hgLayer = (HydrolicGridLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(GridLayerId);
                    if (hgLayer != null) hgLayer.ResetGridData(hg, iBounds);

                    isolineLayer = (IsolineLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(this.IsolineLayerId);
                    if (isolineLayer != null)
                    {
                        isolineLayer.ResetGridData(hg, iBounds);
                        isolineLayer.ContourLineList = new List<ContourLine>();
                        isolineLayer.Redraw();
                    }




                    //流量线图层清空
                    coord3D = AlgorithmHelper.ConvertCoordinatesFor2D(ProjectService.DefaultService.Project.Grid3dData.MainGrid.ModFlowGrid.GetHeadGrid().GridHeads,
                       ProjectService.DefaultService.Project.DisplayOption2.ZMagnification);

                    hg = new HyGrid(gd.RowsCount, gd.ColsCount, gd.LayersCount, gd.RowCoords, gd.ColCoords, gd.LayerCoords, gd.OrgX, gd.OrgY, gd.OrgZ, gd.RotationZ, coord3D);

                    vectorLayer = (FlowVectorLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(VectorLayerID);
                    vectorLayer.SetGrid(hg);
                    vectorLayer.SetVectorValues(null);
                    vectorLayer.Update();

                    break;
                case CollectionChangedType.RESET:

                    gd = ProjectService.DefaultService.Project.Grid3dData.MainGrid.ModFlowGrid;
                    iBounds = gd.WaterGrid.GetIBounds();
                    coord3D = AlgorithmHelper.ConvertCoordinatesFor2D(project.Grid3dData.MainGrid.ModFlowGrid.GetBoundGrid().GridPoints, project.DisplayOption2.ZMagnification);
                    hg = new HyGrid(gd.RowsCount, gd.ColsCount, gd.LayersCount, gd.RowCoords, gd.ColCoords, gd.LayerCoords, gd.OrgX, gd.OrgY, gd.OrgZ, gd.RotationZ, coord3D);

                    hgLayer = (HydrolicGridLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(GridLayerId);
                    if (hgLayer != null) hgLayer.ResetGridData(hg, iBounds);

                    isolineLayer = (IsolineLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(this.IsolineLayerId);
                    if (isolineLayer != null)
                    {
                        isolineLayer.ResetGridData(hg, iBounds);
                        isolineLayer.ContourLineList = new List<ContourLine>();
                        isolineLayer.Redraw();
                    }

                    break;
                default:
                    break;
            }



        }

        /// <summary>
        /// ibound更改触发的操作
        /// </summary>
        protected void OnBoundsChanged()
        {
            HA.ModFlow.Domain.DomainLayer.GridData gd = ProjectService.DefaultService.Project.MfData.GridData;
            DotSpatial.Topology.Coordinate[, ,] coord3D = AlgorithmHelper.ConvertCoordinatesFor2D(ProjectService.DefaultService.Project.Grid3dData.MainGrid.ModFlowGrid.GetBoundGrid().GridPoints, ProjectService.DefaultService.Project.DisplayOption2.ZMagnification);
            HyGrid hg = new HyGrid(gd.RowsCount, gd.ColsCount, gd.LayersCount, gd.RowCoords, gd.ColCoords, gd.LayerCoords, gd.OrgX, gd.OrgY, gd.OrgZ, gd.RotationZ, coord3D);

            List<int[,]> iBounds = gd.WaterGrid.GetIBounds();
            int[, ,] boundary = GetNeededGridInfo.TranslateList2DTo3D(hg, iBounds);

            HydrolicGridLayer hgLayer = (HydrolicGridLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(GridLayerId);
            if (hgLayer != null)
                hgLayer.Boundary = boundary;

            GridSourceSinksLayer gssLayer = (GridSourceSinksLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(RiverLayerId);
            if (gssLayer != null)
                gssLayer.Boundary = boundary;

            gssLayer = (GridSourceSinksLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(WellLayerId);
            if (gssLayer != null)
                gssLayer.Boundary = boundary;

            gssLayer = (GridSourceSinksLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(GHBLayerId);
            if (gssLayer != null)
                gssLayer.Boundary = boundary;

            gssLayer = (GridSourceSinksLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(DrainLayerId);
            if (gssLayer != null)
                gssLayer.Boundary = boundary;

            gssLayer = (GridSourceSinksLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(SpecifiedHeadLayerId);
            if (gssLayer != null)
                gssLayer.Boundary = boundary;

            gssLayer = (GridSourceSinksLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(IBoundLayerId);
            if (gssLayer != null)
            {
                gssLayer.Boundary = boundary;

                List<int[]> ijks = new List<int[]>();
                for (int k = 0; k < gssLayer.Boundary.GetLength(0); k++)
                {
                    for (int j = 0; j < gssLayer.Boundary.GetLength(1); j++)
                    {
                        for (int i = 0; i < gssLayer.Boundary.GetLength(2); i++)
                        {
                            if (gssLayer.Boundary[k, j, i] < 0)
                                ijks.Add(new int[] { j + 1, i + 1, k + 1 });
                        }
                    }


                }
                gssLayer.ClearPoint();
                gssLayer.AddPoint(ijks);
                gssLayer.Redraw();
            }

            BarrierLayer barrierLayer = (BarrierLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(BarrierLayerId);
            if (barrierLayer != null)
                barrierLayer.Boundary = boundary;

            //IsolineLayer isolineLayer = (IsolineLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(IsolineLayerId);
            //if (isolineLayer != null)
            //    isolineLayer.Boundary = boundary;

        }

        /// <summary>
        /// 网格更改触发的操作
        /// </summary>
        protected void OnGridChanged()
        {
            HA.ModFlow.Domain.DomainLayer.GridData gd = ProjectService.DefaultService.Project.Grid3dData.MainGrid.ModFlowGrid;
            DotSpatial.Topology.Coordinate[, ,] coord3D = AlgorithmHelper.ConvertCoordinatesFor2D(ProjectService.DefaultService.Project.Grid3dData.MainGrid.ModFlowGrid.GetBoundGrid().GridPoints, ProjectService.DefaultService.Project.DisplayOption2.ZMagnification);
            HyGrid hg = new HyGrid(gd.RowsCount, gd.ColsCount, gd.LayersCount, gd.RowCoords, gd.ColCoords, gd.LayerCoords, gd.OrgX, gd.OrgY, gd.OrgZ, gd.RotationZ, coord3D);

            HydrolicGridLayer hgLayer = (HydrolicGridLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(GridLayerId);
            if (hgLayer != null) hgLayer.HyGrid = hg;


            GridSourceSinksLayer gssLayer = (GridSourceSinksLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(RiverLayerId);
            if (gssLayer != null) gssLayer.HyGrid = hg;
            gssLayer = (GridSourceSinksLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(WellLayerId);
            if (gssLayer != null) gssLayer.HyGrid = hg;
            gssLayer = (GridSourceSinksLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(GHBLayerId);
            if (gssLayer != null) gssLayer.HyGrid = hg;
            gssLayer = (GridSourceSinksLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(DrainLayerId);
            if (gssLayer != null) gssLayer.HyGrid = hg;
            gssLayer = (GridSourceSinksLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(SpecifiedHeadLayerId);
            if (gssLayer != null) gssLayer.HyGrid = hg;
            gssLayer = (GridSourceSinksLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(IBoundLayerId);
            if (gssLayer != null) gssLayer.HyGrid = hg;

            BarrierLayer barrierLayer = (BarrierLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(BarrierLayerId);
            if (barrierLayer != null) barrierLayer.HyGrid = hg;

            IsolineLayer isolineLayer = (IsolineLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(this.IsolineLayerId);
            if (isolineLayer != null) isolineLayer.HyGrid =hg ;

            //Domain.DomainLayer.GridData gd = ProjectSerivce.DefaultService.Project.Grid3dData.MainGrid.ModFlowGrid;
            coord3D = AlgorithmHelper.ConvertCoordinatesFor2D(ProjectService.DefaultService.Project.Grid3dData.MainGrid.ModFlowGrid.GetHeadGrid().GridHeads,
                ProjectService.DefaultService.Project.DisplayOption2.ZMagnification);

            hg = new HyGrid(gd.RowsCount, gd.ColsCount, gd.LayersCount, gd.RowCoords, gd.ColCoords, gd.LayerCoords, gd.OrgX, gd.OrgY, gd.OrgZ, gd.RotationZ, coord3D);

            FlowVectorLayer vecLayer = (FlowVectorLayer)this.GisManager.LayerSystem.LayerCollection.GetLayer(this.VectorLayerID);
            if (vecLayer != null) vecLayer.Grid = hg;

        }

        /// <summary>
        /// 建立默认图层
        /// </summary>
        protected void BuildDefaultLayer()
        {
            Project project = ProjectService.DefaultService.Project;

            this._defaultMap.BackColor = ProjectService.DefaultService.Project.DisplayOption2.BackColor;

            if (project.AssistData.BitImageIdAndInfoes != null)
            {
                HA.Data.AssistData assData = project.AssistData;

                GroupLayer gl = new GroupLayer(assData.BitImageId);
                gl.Desc = assData.BitImageId;

                foreach (string item in assData.BitImageIdAndInfoes.Keys)
                {
                    ImageLayer imageLayer = new ImageLayer(assData.BitImageIdAndInfoes[item].Id, ProjectService.DefaultService.GetProjPath(ProjPath.RESOURCE) + item);
                    gl.AddChild(imageLayer);
                }

                this._gisManager.LayerSystem.LayerCollection.Add(gl);

            }

            //添加默认的等值线层
            IsolineLayer isolineLayer = new IsolineLayer(IsolineLayerId);
            this._gisManager.LayerSystem.LayerCollection.Add(isolineLayer);
            isolineLayer.Visible = project.DisplayOption2.DoGrid3dData.Grid3d.IsShowContour;
            //刘加，等值线新建时读取主程的设置
            isolineLayer.LineWidth = project.DisplayOption2.DoGrid3dData.Grid3d.Contour.LineWidth;
            isolineLayer.LabelColor = project.DisplayOption2.DoGrid3dData.Grid3d.Contour.ContourLineProperty.LineTagging.TagColor;
            isolineLayer.LabelFont = new System.Drawing.Font("Times New Roman", (float)project.DisplayOption2.DoGrid3dData.Grid3d.Contour.ContourLineProperty.LineTagging.FontSize);
            isolineLayer.IsShowLabel = project.DisplayOption2.DoGrid3dData.Grid3d.Contour.ContourLineProperty.LineTagging.IsShowTagging;
            isolineLayer.LabelNum = project.DisplayOption2.DoGrid3dData.Grid3d.Contour.ContourLineProperty.LineTagging.MaskPointNum;
            isolineLayer.LableFormatNum = project.DisplayOption2.DoGrid3dData.Grid3d.Contour.DecimalDigitNum;
            isolineLayer.IsLabelTextFormat = project.DisplayOption2.DoGrid3dData.Grid3d.Contour.IsSpecifyPrecision;
            isolineLayer.LegendColor = project.DisplayOption2.DoGrid3dData.Grid3d.Contour.ContourLineProperty.LineScalarBar.LabelColor;
            isolineLayer.LegendFont = new System.Drawing.Font("Times New Roman", (float)project.DisplayOption2.DoGrid3dData.Grid3d.Contour.ContourLineProperty.LineScalarBar.LabelFontSize);
            isolineLayer.LegendFormatNum = project.DisplayOption2.DoGrid3dData.Grid3d.Contour.DecimalDigitNum;
            isolineLayer.IsLegendTextFormat = project.DisplayOption2.DoGrid3dData.Grid3d.Contour.IsSpecifyPrecision;
            isolineLayer.IsShowLegend = project.DisplayOption2.DoGrid3dData.Grid3d.Contour.ContourLineProperty.LineScalarBar.IsShowScalarBar;
            isolineLayer.LegendHeight =(float) project.DisplayOption2.DoGrid3dData.Grid3d.Contour.ContourLineProperty.LineScalarBar.Height / 100;
            isolineLayer.LegendWidth = (float)project.DisplayOption2.DoGrid3dData.Grid3d.Contour.ContourLineProperty.LineScalarBar.Width / 100 * this._defaultMap.Width;
            isolineLayer.LegendOffsetX = (double)ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Contour.ContourLineProperty.LineScalarBar.XToViewPortLeftUper / 100 * this.GisManager.CurrentMap.Width;
            isolineLayer.LegendOffsetY = (double)ProjectService.DefaultService.Project.DisplayOption2.DoGrid3dData.Grid3d.Contour.ContourLineProperty.LineScalarBar.YToViewPortLeftUper / 100 * this.GisManager.CurrentMap.Height;
            //反距离权重插值参数初始化
            isolineLayer.NodalFunctionType = project.InterpolationOption2D.IdwOption.NodalFunction;
            isolineLayer.Nq = project.InterpolationOption2D.IdwOption.Nq;
            isolineLayer.Nw = project.InterpolationOption2D.IdwOption.Nw;
            //克里金插值参数初始化
            //待添加

            //添加流动向量表现层
            FlowVectorLayer vectorLayer  = new FlowVectorLayer(VectorLayerID, null, null);
            this._gisManager.LayerSystem.LayerCollection.Add(vectorLayer);
            vectorLayer.Visible = project.DisplayOption2.DoGrid3dData.Grid3d.IsShowVector;
            //刘加，向量图层新建时读取主程的设置
            vectorLayer.IsUseVaryLength = project.DisplayOption2.DoGrid3dData.Grid3d.Vector.IsVaryLength;
            vectorLayer.LineColor = project.DisplayOption2.DoGrid3dData.Grid3d.Vector.VectorColor;
            vectorLayer.VectorLength = project.DisplayOption2.DoGrid3dData.Grid3d.Vector.Length;
            vectorLayer.ScaleRatio = project.DisplayOption2.DoGrid3dData.Grid3d.Vector.Scaling;
            

            //添加gridLayer所属的默认group
            GroupLayer gridGroupLayer = new GroupLayer(GridGroupLayerId);
            this._gisManager.LayerSystem.LayerCollection.Add(gridGroupLayer);

            //添加离散点集合默认group
            GroupLayer scatterPointGroupLayer = new GroupLayer(Scatter2DGroupLayerId);
            this._gisManager.LayerSystem.LayerCollection.Add(scatterPointGroupLayer);

            //添加源汇所属的默认group
            GroupLayer modFlowGroupLayer = new GroupLayer(ModFlowLayerId);
            this._gisManager.LayerSystem.LayerCollection.Add(modFlowGroupLayer);


            #region 废弃测试代码

            //if (project.MapData.GridFrame != null)
            //{

            //    GridFrame gf = project.MapData.GridFrame;


            //    ConceptFrameLayer cl = new ConceptFrameLayer(gf.Key.ToString(), new RectangleFrame(new Coordinate(gf.XOrg, gf.YOrg, 0), gf.XLength, gf.YLength, gf.RotateAngle));

            //    this._gisManager.LayerSystem.LayerCollection.Add(cl);

            //}

            //DOMap doMap = project.DisplayOption.Map;

            //foreach (ConceptualModel item in project.MapData.ConceptualModelCL)
            //{

            //    GroupLayer gl = new GroupLayer(item.Key.ToString());
            //    gl.Desc = item.Name;

            //    foreach (Coverage coverage in item.Coverages)
            //    {
            //        VectorLayer vl = new VectorLayer(coverage.Key.ToString());
            //        vl.Desc = coverage.Name;

            //        //提供switch对应转换方法  type 待写
            //        vl.ShapeStyleAndIdStorage.Add(CONCEPTLAYERSOURCESINK.BARRIER, new ConceptShapesStorageAndDisplayStyle(doMap.Barrier.Color, 8, DotSpatial.Symbology.PointShape.Ellipse));
            //        vl.ShapeStyleAndIdStorage.Add(CONCEPTLAYERSOURCESINK.DRAIN, new ConceptShapesStorageAndDisplayStyle(doMap.Drain.Color, 8, DotSpatial.Symbology.PointShape.Ellipse));
            //        vl.ShapeStyleAndIdStorage.Add(CONCEPTLAYERSOURCESINK.GENERALHEAD, new ConceptShapesStorageAndDisplayStyle(doMap.GeneralHead.Color, 8, DotSpatial.Symbology.PointShape.Ellipse));
            //        //vl.ShapeStyleAndIdStorage.Add(CONCEPTLAYERSOURCESINK.LAKE, new ConceptShapesStorageAndDisplayStyle(doMap..Color, 8, DotSpatial.Symbology.PointShape.Ellipse));
            //        //vl.ShapeStyleAndIdStorage.Add(CONCEPTLAYERSOURCESINK.LAYERRANGE, new ConceptShapesStorageAndDisplayStyle(doMap.lay.Color, 8, DotSpatial.Symbology.PointShape.Ellipse));
            //        vl.ShapeStyleAndIdStorage.Add(CONCEPTLAYERSOURCESINK.NONE, new ConceptShapesStorageAndDisplayStyle(System.Drawing.Color.Black, 8, DotSpatial.Symbology.PointShape.Ellipse));
            //        //vl.ShapeStyleAndIdStorage.Add(CONCEPTLAYERSOURCESINK.OBSERVEDFLOW, new ConceptShapesStorageAndDisplayStyle(doMap..Color, 8, DotSpatial.Symbology.PointShape.Ellipse));
            //        //vl.ShapeStyleAndIdStorage.Add(CONCEPTLAYERSOURCESINK.REFINEPOINTS, new ConceptShapesStorageAndDisplayStyle(doMap.refin.Color, 8, DotSpatial.Symbology.PointShape.Ellipse));
            //        vl.ShapeStyleAndIdStorage.Add(CONCEPTLAYERSOURCESINK.RIVER, new ConceptShapesStorageAndDisplayStyle(doMap.River.Color, 8, DotSpatial.Symbology.PointShape.Ellipse));
            //        vl.ShapeStyleAndIdStorage.Add(CONCEPTLAYERSOURCESINK.SEEPAGEFACE, new ConceptShapesStorageAndDisplayStyle(doMap.Seepage.Color, 8, DotSpatial.Symbology.PointShape.Ellipse));
            //        vl.ShapeStyleAndIdStorage.Add(CONCEPTLAYERSOURCESINK.SPECIFIEDFLOW, new ConceptShapesStorageAndDisplayStyle(doMap.SpecifiedFlow.Color, 8, DotSpatial.Symbology.PointShape.Ellipse));
            //        vl.ShapeStyleAndIdStorage.Add(CONCEPTLAYERSOURCESINK.SPECIFIEDHEAD, new ConceptShapesStorageAndDisplayStyle(doMap.SpecifiedHead.Color, 8, DotSpatial.Symbology.PointShape.Ellipse));
            //        //vl.ShapeStyleAndIdStorage.Add(CONCEPTLAYERSOURCESINK.TANSOBSERVEDFLOW, new ConceptShapesStorageAndDisplayStyle(doMap.tan.Color, 8, DotSpatial.Symbology.PointShape.Ellipse));
            //        vl.ShapeStyleAndIdStorage.Add(CONCEPTLAYERSOURCESINK.WELL, new ConceptShapesStorageAndDisplayStyle(doMap.Well.Color, 8, DotSpatial.Symbology.PointShape.Ellipse));



            //        gl.AddChild(vl);
            //    }

            //    this._gisManager.LayerSystem.LayerCollection.Add(gl);


            //}

            //foreach (CoverageBase item in project.MapData.Coverages)
            //{
            //    if (item is Coverage)
            //    {
            //        VectorLayer vl = new VectorLayer(item.Key.ToString());
            //        vl.Desc = item.Name;
            //        this._gisManager.LayerSystem.LayerCollection.Add(vl);

            //    }

            //    if (item is ConceptualModel)
            //    {
            //        GroupLayer gl = new GroupLayer(item.Key.ToString());
            //        gl.Desc = item.Name;

            //        this._gisManager.LayerSystem.LayerCollection.Add(gl);
            //    }


            //}


            //if (project.Grid3dData.Grids.Count > 0)
            //{



            //    Grid3d gd = project.Grid3dData.MainGrid;


            //    DotSpatial.Topology.Coordinate[, ,] coord3D = AlgorithmHelper.ConvertCoordinatesFor2D(project.Grid3dData.MainGrid.ModFlowGrid.GetBoundGrid().GridPoints);
            //    HyGrid hg = new HyGrid
            //        (
            //        gd.ModFlowGrid.RowsCount, gd.ModFlowGrid.ColsCount, gd.ModFlowGrid.LayersCount,
            //        gd.ModFlowGrid.RowCoords, gd.ModFlowGrid.ColCoords, gd.ModFlowGrid.LayerCoords, gd.ModFlowGrid.OrgX,
            //        gd.ModFlowGrid.OrgY, gd.ModFlowGrid.OrgZ, gd.ModFlowGrid.RotationZ, coord3D
            //        );

            //    ///测试网格
            //    ///
            //    HydrolicGridLayer hgLayer = new HydrolicGridLayer(gd.Key.ToString(), hg, gd.ModFlowGrid.WaterGrid.GetIBounds());

            //    hgLayer.Desc = gd.Name;

            //    // HydrolicGridLayer hg = new HydrolicGridLayer(gd.Name,hg);


            //    this._gisManager.LayerSystem.LayerCollection.Add(hgLayer);

            //    ///测试数据
            //    ///
            //    if (project.MfData != null)
            //    {
            //        List<int[]> testers = new List<int[]>();
            //        GridSourceSinksLayer gssLayer = new GridSourceSinksLayer("RIVER", hg, gd.ModFlowGrid.WaterGrid.GetIBounds(), testers, FMAPVIEW.NORMAL, 1);
            //        this._gisManager.LayerSystem.LayerCollection.Add(gssLayer);


            //        gssLayer = new GridSourceSinksLayer("WELL", hg, gd.ModFlowGrid.WaterGrid.GetIBounds(), testers, FMAPVIEW.NORMAL, 1);
            //        this._gisManager.LayerSystem.LayerCollection.Add(gssLayer);
            //        gssLayer.SetFeatureDisplayStyle(MFSOURCESINKSDISPLAYMODE.Diamond, System.Drawing.Color.BlueViolet, 10);

            //        gssLayer = new GridSourceSinksLayer("GHB", hg, gd.ModFlowGrid.WaterGrid.GetIBounds(), testers, FMAPVIEW.NORMAL, 1);
            //        this._gisManager.LayerSystem.LayerCollection.Add(gssLayer);
            //        gssLayer.SetFeatureDisplayStyle(MFSOURCESINKSDISPLAYMODE.Rectangle, System.Drawing.Color.LawnGreen, 8);


            //        gssLayer = new GridSourceSinksLayer("Drain", hg, gd.ModFlowGrid.WaterGrid.GetIBounds(), testers, FMAPVIEW.NORMAL, 1);
            //        this._gisManager.LayerSystem.LayerCollection.Add(gssLayer);
            //        gssLayer.SetFeatureDisplayStyle(MFSOURCESINKSDISPLAYMODE.Star, System.Drawing.Color.Orange, 10);
            //        //((DotSpatial.Symbology.PointSymbolizer)(gssLayer.ILayer as MapPointLayer).Symbolizer).Symbols[0].Angle

            //        gssLayer = new GridSourceSinksLayer("SPECIFIEDHEAD", hg, gd.ModFlowGrid.WaterGrid.GetIBounds(), testers, FMAPVIEW.NORMAL, 1);
            //        this._gisManager.LayerSystem.LayerCollection.Add(gssLayer);
            //        gssLayer.SetFeatureDisplayStyle(MFSOURCESINKSDISPLAYMODE.Diamond, System.Drawing.Color.YellowGreen, 10);

            //        gssLayer = new GridSourceSinksLayer("IBound", hg, gd.ModFlowGrid.WaterGrid.GetIBounds(), testers, FMAPVIEW.NORMAL, 1);
            //        this._gisManager.LayerSystem.LayerCollection.Add(gssLayer);
            //        gssLayer.SetFeatureDisplayStyle(MFSOURCESINKSDISPLAYMODE.Hexagon, System.Drawing.Color.LightSeaGreen, 10);
            //    }


            //}

            #endregion

            this._gisManager.CurrentMap.FunctionMode = FunctionMode.Pan;
            this._gisManager.CurrentMap.ZoomToMaxExtent();

        }

        #endregion

        #region 公共函数

        public List<int> GetGridSelectedCellIndexes()
        {
            HydrolicGridLayer layer = (HydrolicGridLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(GridLayerId);

            if (layer != null)
                return layer.SelectedCellIndexes;

            return new List<int>();
        }


        public void ZoomToExtent()
        {
            this._gisManager.ZoomToExtent();
        }

        /// <summary>
        /// 视图当前层切换操作
        /// </summary>
        /// <param name="num"></param>
        public void SetGridLayerNum(int num)
        {
            if (ProjectService.DefaultService.Project.Grid3dData.MainGrid != null)
            {
                this.DefaultMap.Layers.SuspendEvents();

                HydrolicGridLayer hgLayer = (HydrolicGridLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(GridLayerId);
                if (hgLayer != null)
                {
                    hgLayer.ViewLayerIndex = num;

                }

                List<Point> centroidPoints = GetNeededGridInfo.ComputeCentroidForLayerCells(hgLayer.GridPolygons);

                GridSourceSinksLayer gssLayer = (GridSourceSinksLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(RiverLayerId);
                if (gssLayer != null)
                {
                    gssLayer.CentroidPoints = centroidPoints;
                    gssLayer.ViewLayerIndex = num;
                }

                gssLayer = (GridSourceSinksLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(WellLayerId);
                if (gssLayer != null)
                {
                    gssLayer.CentroidPoints = centroidPoints;
                    gssLayer.ViewLayerIndex = num;
                }

                gssLayer = (GridSourceSinksLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(GHBLayerId);
                if (gssLayer != null)
                {
                    gssLayer.CentroidPoints = centroidPoints;
                    gssLayer.ViewLayerIndex = num;
                }

                gssLayer = (GridSourceSinksLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(DrainLayerId);
                if (gssLayer != null)
                {
                    gssLayer.CentroidPoints = centroidPoints;
                    gssLayer.ViewLayerIndex = num;
                }

                gssLayer = (GridSourceSinksLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(SpecifiedHeadLayerId);
                if (gssLayer != null)
                {
                    gssLayer.CentroidPoints = centroidPoints;
                    gssLayer.ViewLayerIndex = num;
                }

                gssLayer = (GridSourceSinksLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(IBoundLayerId);
                if (gssLayer != null)
                {
                    gssLayer.CentroidPoints = centroidPoints;
                    gssLayer.ViewLayerIndex = num;
                }

                BarrierLayer barrierLayer = (BarrierLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(BarrierLayerId);
                if (barrierLayer != null)
                {
                    barrierLayer.ViewLayerIndex = num;
                }

                IsolineLayer isolineLayer = (IsolineLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(IsolineLayerId);
                if (isolineLayer != null)
                {
                    if (isolineLayer.HyGrid != null)
                        isolineLayer.ViewLayerIndex = num;
                }

                //刘加，向量图层
                FlowVectorLayer vectorLayer = (FlowVectorLayer)this._gisManager.LayerSystem.LayerCollection.GetLayer(VectorLayerID);
                if (vectorLayer != null && vectorLayer.Grid != null && vectorLayer.VectorValues != null)
                {
                    vectorLayer.LayerIndex = num;
                }

                this.DefaultMap.Layers.ResumeEvents();
                this.DefaultMap.Invalidate();
            }

            this._gisManager.ZoomToExtent();
        }

        /// <summary>
        /// 设置gis当前图层
        /// </summary>
        /// <param name="layerId"></param>
        public void SetCurrentLayer(string layerId)
        {
            this._gisManager.InteractiveSystem.CurrentLayer = this._gisManager.LayerSystem.LayerCollection.GetLayer(layerId);
        }

        /// <summary>
        /// 设置指定图层的可见性
        /// </summary>
        /// <param name="layerId"></param>
        /// <param name="isVisible"></param>
        public void SetLayerVisible(string layerId, bool isVisible)
        {
            Layer layer = this._gisManager.LayerSystem.LayerCollection.GetLayer(layerId);
            if (layer != null)
                layer.Visible = isVisible;
        }

        #endregion


        public EventHandler barrier_Click { get; set; }
    }
}
